Home  >  Article  >  Web Front-end  >  Several examples of problems with one-dimensional arrays and two-dimensional arrays in js_Basic knowledge

Several examples of problems with one-dimensional arrays and two-dimensional arrays in js_Basic knowledge

WBOY
WBOYOriginal
2016-05-16 16:41:451143browse

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;
Statement:
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