3 回答

TA貢獻1946條經驗 獲得超4個贊
因此,chrome 的 DevTools 中數組旁邊的數字只是告訴您數組中有多少項。
這不是實際的數組
如果您想編輯數組或只是訪問元素,有多種方法
看這個例子:
let someArray = [
[1,"a",2.3],
[2,"b",7.8],
[3,"c",4.5],
]
// if you want to change the items inside the array
//Array.map
someArray = someArray.map(innerArray =>{
return innerArray.map(element => {
//Do any thing to the element lets say that we want to convert all values to strings
return String(element);
})
})
console.log(someArray);
console.log('##################################');
//if you don't want to change the items inside the arreay you can:
// 1. remove the return statement from the Array.map function above
// 2. use any type of loop for, while loop
for(let i = 0; i < someArray.length; i++){
for(let j = 0; j < someArray[i].length; j++){
// Do any thing with the array item lets say you want to print it
console.log(someArray[i][j]);
}
}

TA貢獻1796條經驗 獲得超7個贊
下面將打印二維數組上的每個字符串
array.forEach((childArr) => childArr.forEach((str) => console.log(str)))

TA貢獻1873條經驗 獲得超9個贊
您的控制臺在每個元素內容之前顯示索引。
在你的例子中,每個元素也是一個數組。
因此,為了映射您的特定數組:
let newArray = array.map(innerArray => insideArray.map(element => {你的代碼}));
添加回答
舉報