我在流中有一个值数组,您希望通过管道传输它,以便它将逐个发出数组值,并等待它们全部完成,然后再处理另一个数组
// This is the array:
let arr = [[1,2,3], [4,5,6]];
let data = arr.filter( (value) => {
let newdata = value.filter((newVal, index) => {
if (newVal !== value[index]) {
return '' ;
}
});
});
console.log(data);
// Output: []
// Expected output: [[], []]
最佳答案
arr.map(x => x.map((y, index) => {if(y !== y[index]){return ''}}))
这将返回[["", "", ""], ["", "", ""]]
对于[[], []]
过滤掉那些空白字符串:
arr.map(x => x.map((y, index) => {if(y !== y[index]){return ''}}).filter(z => z !== ""))
关于javascript - 如何在javascript中对数组进行一一处理?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/60316419/