js 数组里面去重和判空

    1.先定义一个新数组
        let newArr = []
        let tempRes = res.data.instructionsUrl.split(",");//先把返回来的数据用逗号分割成数组
        for(let j=0;j<tempRes.length;j++){
            if(tempRes[j] != "" && tempRes[j] != null && tempRes != undefined && this.mod_response_images.indexOf(tempRes[j]) < 0){ //在新的数组里面内部不存在才追加
                newArr.push(tempRes[j]) //压入新的数组
            }
        }

猜你喜欢

转载自my.oschina.net/u/3312137/blog/1789235