我得到的areas是字符串,然后我把他们放到数组里面,最后进行去重操作,得出的结果不对,请问怎么修改代码可去进行去重得到[4662,4663]areas += choiceID[0].areas[i].id + ',';
console.log('areas is:', areas) // areas is: 4662,4663,4662,4663,var arrAreas = []
arrAreas.push(areas)
console.log(arrAreas) // ["4662,4663,4662,4663,"]var newAreas = [...new Set(arrAreas)]
console.log(newAreas) // ["4662,4663,4662,4663,"]
2 回答
侃侃无极
TA贡献2051条经验 获得超10个赞
你的数组没取对呢 是 ["4662", "4663", "4662", "4663"] 而不是 ["4662,4663,4662,4663"]var areas = '4662,4663,4662,4663'var arrAreas = areas.split(',') console.log(arrAreas)var newAreas = [...new Set(arrAreas)] console.log(newAreas)
- 2 回答
- 0 关注
- 152 浏览
添加回答
举报
0/150
提交
取消