Home > Article > Web Front-end > Analysis on JavaScript associative array usage
This article mainly introduces JavaScriptAssociationArray usage, and analyzes the concept, definition and implementation skills related to traversal operations of associative arrays in the form of examples. Friends in need can refer to the following
The examples in this article describe the usage of Javascript associative arrays. Share it with everyone for your reference, the details are as follows:
Basic concept:
"Associative array" is an array with a special indexing method . Not only can it be indexed by integers, but also by stringsor 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?
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 Analysis on JavaScript associative array usage. For more information, please follow other related articles on the PHP Chinese website!