Home >Web Front-end >JS Tutorial >JavaScript associative array usage analysis

JavaScript associative array usage analysis

不言
不言Original
2018-05-05 13:58:001905browse

This article mainly introduces the usage of JavaScript associative arrays, and analyzes the concepts, definitions and implementation techniques related to traversal operations of associative arrays in the form of examples. Friends in need can refer to it

The examples in this article describe JavaScript associations Array usage. Share it with everyone for your reference, the details are as follows:

Basic concept:

"Associative array" is an array with a special indexing method. You can index it not only by integers, but also by strings or other types of values ​​(except NULL). The index value of an associative array is an arbitrary scalar. These scalars are called Keys and can be used to retrieve values ​​in the array later. The elements of an associative array have no specific order.

What does an associative array look like?

Copy code The code is as follows:

var defs = [W3C: "World Wide Web Consortium", DOM: "Document Object Model"];

How to define an associative array?

var defs = [];
defs[key] = value;

Note: key and value need to be assigned different values ​​respectively.

How to traverse an associative array?

for (key in defs) {
  // 变量 key 可以直接使用。
  var value = defs[key]; //每个key对于的值。
}

The above is the detailed content of JavaScript associative array usage analysis. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn