Home>Article>Web Front-end> Is there a list type in javascript?
There is no list data type in JavaScript. The List type is to solve the problem of immutable array length, but JavaScript does not have this problem. Most of the functions of List are also available in JavaScript arrays.
The operating environment of this tutorial: Windows 10 system, JavaScript version 1.8.5, Dell G3 computer.
Does JavaScript have a list type?
JavaScript can define array types, but there is no so-called List type.
There is no need for the List type to exist in JavaScript. JAVA's List type is to solve the problem of immutable array length, but JavaScript does not solve this problem. JavaScript arrays have variable lengths and have many practical methods that can be used. They are much more flexible than JAVA arrays. Most of the functions of JAVA's List are also available in JavaScript arrays.
There are several ways to define arrays in JavaScript:
var arr = []; //Define an empty array
var arr = [1,2,3];//Define an array with elements
##var arr = new Array();//Define an empty array, verbose The writing method var arr = new Array(5);//Define an array with a length of 5, which is easily misleading and is a very not recommended writing method Extended reading: Methods of array objects concat() Concatenates two or more arrays and returns the result. copyWithin() Copy elements from the specified position in the array to another specified position in the array. entries() Returns an iterable object of the array. every() Check whether each element of the numerical element meets the conditions. fill() Fills the array with a fixed value. 【Related recommendations:The above is the detailed content of Is there a list type in javascript?. For more information, please follow other related articles on the PHP Chinese website!