有这样一个数组A(级联
this.arr = this.optionsCity.filter((o) => {
if (o.areaName == this.valueCity[this.valueCity.length - 1]) {
console.log('00000')
return o
}else{
// o.children.filter((i) => {
// console.log('2222')
// return i.areaName == this.valueCity[this.valueCity.length - 1]
// })
}
})
你可以使用数组的 filter() 方法以及对象的 areaName 属性来实现这个需求,具体的代码如下:
// 假设数组 A 中每个元素都是一个对象,其中包含 areaName 属性
const A = [ { areaName: "北京市", otherProp: "其他属性" }, { areaName: "上海市", otherProp: "其他属性" }, { areaName: "北京市", otherProp: "其他属性" }]
// 假设数组 B 中只包含一个元素,该元素是一个字符串
const B = ["北京市"]
// 根据 B 中的值,从 A 中筛选出 areaName 属性等于该值的元素
const filteredA = A.filter((element) => element.areaName === B[0])
console.log(filteredA)
如果有帮您解决问题,麻烦点一下采纳,谢谢。