Home > Web Front-end > JS Tutorial > body text

JavaScript associative array usage analysis

不言
Release: 2018-05-05 13:58:00
Original
1881 people have browsed it

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"];
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 JavaScript associative array usage analysis. 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