Home > Web Front-end > Front-end Q&A > What are array elements in Javascript

What are array elements in Javascript

青灯夜游
Release: 2021-06-22 17:52:35
Original
2385 people have browsed it

In Javascript, each value stored in an array is called an array element, which is the basic unit that makes up an array. Array elements are also a type of variable, and are identified by the array name followed by a subscript. The subscript represents the sequence number of the element in the array; array elements are often also called subscript variables.

What are array elements in Javascript

The operating environment of this tutorial: windows7 system, javascript version 1.8.5, Dell G3 computer.

Array Array object is a built-in object of JS. It can use a variable to store a series of values ​​of the same or different types. Each value stored in it is called an array element.

Array elements are the basic units that make up an array. Array elements are also variables, identified by the array name followed by a subscript. The subscript represents the sequence number of the element in the array. Array elements are also often called subscript variables.

Reference of JS array elements

Each element stored in the array has a position index (also called a subscript). The array subscript starts from 0 and ends with The array length ends at -1, that is, the index of the first element is 0, and the index of the last element is array length-1.

When referencing array elements, you can use the array name and subscript. The reference format is as follows:

数组名[元素下标]
Copy after login

For example: the 3 elements of an array named arr containing 3 elements can be used respectively. Referenced via: arr[0], arr[1] and arr[2].

JS array access

There are two ways to access the array:

  • One is to directly access the array name. At this time Will return all element values ​​stored in the array. For example, alert(hobbies1), after execution of this statement, all element values ​​stored in the hobbies1 array created above will be output in the warning dialog box: travel, sports, music;

  • The second is Use array plus subscript access, in which case the array element value corresponding to the array subscript will be returned. For example: alert(hobbies1[1]), after this statement is executed, "Motion" will be output in the warning dialog box.

[Related recommendations: javascript learning tutorial]

The above is the detailed content of What are array elements in Javascript. 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