亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

映射嵌套數組?

映射嵌套數組?

紅顏莎娜 2023-09-28 15:32:53
對于菜鳥問題感到抱歉,但我想知道如何在數組前面映射一個數字?array = [            ['geeks', '4', 'geeks' ],            ['Hello', 'test', 'jeff'],            ['Test', 'Pli', 'alphabet']        ]我正在嘗試循環在控制臺中輸出的數據我需要循環并顯示所有數組的數據
查看完整描述

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]);

      

  }


}


查看完整回答
反對 回復 2023-09-28
?
蕪湖不蕪

TA貢獻1796條經驗 獲得超7個贊

下面將打印二維數組上的每個字符串

array.forEach((childArr) => childArr.forEach((str) => console.log(str)))


查看完整回答
反對 回復 2023-09-28
?
眼眸繁星

TA貢獻1873條經驗 獲得超9個贊

您的控制臺在每個元素內容之前顯示索引。

在你的例子中,每個元素也是一個數組。

因此,為了映射您的特定數組:

let newArray = array.map(innerArray => insideArray.map(element => {你的代碼}));


查看完整回答
反對 回復 2023-09-28
  • 3 回答
  • 0 關注
  • 143 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號