Home > Article > Web Front-end > Several examples of problems with one-dimensional arrays and two-dimensional arrays in js_Basic knowledge
Arrays in js can store various data types (numeric values, strings)
The array in js does not cross the boundary. When the output array subscript crosses the boundary, undefined will be displayed.
Arrays in js grow dynamically by default
A simple way to iterate over an array.
for(var key in arr){ window.alert(key+"= "+arr[key]); }
Problems that occur when assigning values to an empty two-dimensional array:
var arr2=[]; arr2[1][1]=45;//js不支持这种赋值方法
Solution:
//在这之前需要初始化定义arr2有多少行。 for(var i=0;i<5;i++){ arr2[i]=[]; } //这样就能对它赋值了。 arr2[1][1]=45;