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

Analysis on JavaScript associative array usage

黄舟
Release: 2017-03-17 15:20:57
Original
1267 people have browsed it

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"];
Copy after login

How to define an associative array?

var defs = [];
defs[key] = value;
Copy after login

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对于的值。
}
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template