筛选(数组里竖向都为0的删除)

let arr = [
    [0, 0, 0, 0, 0, 1, 5, 6, 0, 0, 0, 0],
    [0, 0, 0, 0, 3, 1, 5, 6, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 1, 5, 6, 0, 4, 0, 0],
    [0, 0, 1, 0, 0, 1, 5, 6, 0, 0, 3, 0],
    [0, 0, 0, 0, 2, 1, 5, 6, 0, 0, 0, 0],
    [0, 0, 0, 0, 0, 1, 5, 6, 0, 0, 0, 0]
]
let i = 0
for (i = 0; i < arr[0].length; i++) {
    let iso = arr.every((item) => {
        return item[i] === 0
    })
    if (iso) {
        arr = arr.map((item) => {
            item.splice(i, 1)
            return item
        })
        i--
    }
}
console.log('arr', arr)
arr = [
	[0, 0, 1, 5, 6, 0, 0],
	[0, 3, 1, 5, 6, 0, 0],
	[0, 0, 1, 5, 6, 4, 0],
	[1, 0, 1, 5, 6, 0, 3],
	[0, 2, 1, 5, 6, 0, 0],
	[0, 0, 1, 5, 6, 0, 0]
]

你可能感兴趣的:(JavaScript基础)