我有一个数组的数组:
[["email", "test@test.com"], ["phone", 123123123], ["address", "street"]]
我想创建一个数组,每个数组中只有第一个元素:
["email", "phone", "address"]
我有这样的东西:
bigArray.map((field) => {
this.smallArray.add(field[0]);
});
但是我得到了错误:Error in event handler for "bigArray": "TypeError: _this.smallArray.add is not a function"
如何解决这个问题?
const arr = [["email", "test@test.com"], ["phone", 123123123], ["address", "street"], ["sameple"]]
const result = arr
.filter(a => !!a[1])
.map(a => a[0])
console.log(result)
this.smallArray = this.bigArray.map(arr => arr[0])
我认为您正在尝试向smallArray
添加过滤元素。你应该使用。
this.smallArray.push(field[0]);