Home >Web Front-end >JS Tutorial >About the declaration method of two-dimensional array in JS

About the declaration method of two-dimensional array in JS

高洛峰
高洛峰Original
2017-01-14 10:48:371386browse

As shown below:

var myarr=new Array(); //先声明一维
for(var i=0;i<2;i++){  //一维长度为2
  myarr[i]=new Array(); //再声明二维
  for(var j=0;j<3;j++){  //二维长度为3
    myarr[i][j]=i+j;  // 赋值,每个数组元素的值为i+j
  }
}

The above is the entire content of the declaration method of two-dimensional arrays in JS brought to you by the editor. I hope it will be helpful to everyone. Please support the PHP Chinese website~

For more related articles about the declaration method of two-dimensional arrays in JS, please pay attention to the PHP Chinese website!

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