vue.js如何实现数组去重
时间:2022-02-11 17:46
vue.js实现数组去重的方法:使用两个for循环来判断每一项的id,如【that.positions.map(train=>{that.new_Positions.push( train.trainId)})that.resul...】。 本文操作环境:windows10系统、vue 2.5.2、thinkpad t480电脑。 vue.js中实现数组去重可以考虑使用for循环和... new set两种方式来实现,一起来看下吧! 第一种方法: 用2个for循环,判断每一项的id 具体代码如下: 打印的结果: 第二种方法: 用... new set 实现 具体代码如下: 学习推荐:php培训 以上就是vue.js如何实现数组去重的详细内容,更多请关注gxlsystem.com其它相关文章! // that.positions.map(train=>{
// that.new_Positions.push( train.trainId)
// })
// that.resultArr = [];//去重后的数组
// var flag;
// for (var i in that.new_Positions){
// flag = true;
// for (var j in that.resultArr) {
// if (that.resultArr[j] == that.new_Positions[i]) {
// flag = false;
// break;
// }
// }
// if (flag) {
// that.resultArr.push(that.new_Positions[i]);
// }
// }
// console.log("that.resultArr:",that.resultArr)
that.positions.map(train=>{
that.new_Positions.push(train.trainId)
})
that.new_Positions = [...new Set(that.new_Positions)];
console.log("that.resultArr:",that.new_Positions)