Home >Web Front-end >JS Tutorial >Associative array issues in JavaScript_Basic knowledge
The beatles array above is a typical example of a traditional array: the subscript of each element is a number, and each time an element is added, the number increases by 1. The index of the first element is 0, and the index of the second element is 1. And so on.
If only the values of the elements are given when filling the array, the array will be a traditional array, and the subscripts of its individual elements will be automatically created and refreshed.
This default behavior can be changed by explicitly giving the subscript for each new element when filling the array. When giving subscripts for new elements, you are not limited to using integer numbers. You can also use strings:
Such an array is called an associative array. Because you can use strings instead of numeric values, the code is more readable. However, this usage is not a good habit and is not recommended for everyone. Essentially, when you create an associative array, you create properties of the Array object. In JavaScript, all variables are actually objects of some type. For example, a Boolean value is an object of type Boolean, and an array is an object of type Array. In the above example, you actually added the name, year and living attributes to the lennon array. Ideally, you should not modify the properties of an Array object, but instead use a generic Object.
The above is the entire content of this article, I hope you all like it.