获取二维数组javascript中所有0索引数据
let a = [["", "2", "", ""], ["1", "3", "", ""], ["", "", "4", ""]]
index = 0
output = ["", "1", ""]
同样获取所有剩余索引数据
index= 1
output = ["2", "3", ""]
最佳答案
您可以使用Array#map
方法 ES6 destructuring feature 。解构有助于从对象中提取某些属性(Javascript Array也是一个对象)。
let a = [
["", "2", "", ""],
["1", "3", "", ""],
["", "", "4", ""]
];
let index = 0;
let output = a.map(({[ index ]: v }) => v)
console.log(output);
index = 1;
output = a.map(({[ index ]: v }) => v)
console.log(output);
关于javascript - 在 2d Array Javascript 中查找零索引数据,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55087344/