Some examples of problems in one dimensional arrays and two bit arrays in js are illustrated

  • 2020-03-30 03:34:34
  • OfStack

An array in js that can hold various data types (numeric values, strings)

The array in js is not out of bounds, and when the index of the output array is out of bounds, it is undefined.

Arrays in js are dynamically grown by default

A simple way of traversing groups.


for(var key in arr){
window.alert(key+"= "+arr[key]);
}

Problems with assigning values to an empty two-dimensional array:


var arr2=[];
arr2[1][1]=45;//js This method of assignment is not supported 

Solutions:


//Before we do that, we need to initialize to define how many rows arr2 has.
for(var i=0;i<5;i++){
arr2[i]=[];
}
//So we can assign a value to it.
arr2[1][1]=45;

Related articles: