映射嵌套数组?

对于菜鸟问题感到抱歉,但我想知道如何在数组前面映射一个数字?


array = [

            ['geeks', '4', 'geeks' ],

            ['Hello', 'test', 'jeff'],

            ['Test', 'Pli', 'alphabet']

        ]

我正在尝试循环在控制台中输出的数据


我需要循环并显示所有数组的数据


红颜莎娜
浏览 103回答 3
3回答

绝地无双

因此,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.mapsomeArray = someArray.map(innerArray =>{&nbsp; return innerArray.map(element => {&nbsp; &nbsp; //Do any thing to the element lets say that we want to convert all values to strings&nbsp; &nbsp;&nbsp;&nbsp; &nbsp; return String(element);&nbsp; })})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 loopfor(let i = 0; i < someArray.length; i++){&nbsp; for(let j = 0; j < someArray[i].length; j++){&nbsp; &nbsp; &nbsp; // Do any thing with the array item lets say you want to print it&nbsp; &nbsp; &nbsp; console.log(someArray[i][j]);&nbsp; &nbsp; &nbsp;&nbsp;&nbsp; }}

芜湖不芜

下面将打印二维数组上的每个字符串array.forEach((childArr)&nbsp;=>&nbsp;childArr.forEach((str)&nbsp;=>&nbsp;console.log(str)))

眼眸繁星

您的控制台在每个元素内容之前显示索引。在你的例子中,每个元素也是一个数组。因此,为了映射您的特定数组:let newArray = array.map(innerArray => insideArray.map(element => {你的代码}));
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript