匹配的value值是字符串类型,如果是number类型,includes()和indexOf()不可用。详看定义:
方法一:Object.entries(),includes(),splice()
方法二:indexOf(),splice()
let arr =[ { key: 1, second: 1, value: "美妆" },{ key: 1, second: 1, value: "啊美没", },{ key: 72, second: 1, value: "颜值达人", } ] for(let [key,val] of Object.entries(arr)){ if('啊美没'.includes(val.value)){ arr.splice(key,1) } } console.log(arr) // [{key: 1,second: 1,value: "美妆"},{key: 72,second: 1,value: "颜值达人"}] for(let i=0;i<arr.length;i++){ if((arr[i].value).indexOf('人')>-1){ arr.splice(i,1); } } console.log(arr) //[{key: 1,second: 1,value: "美妆"}]
标签:splice,arr,数组,对象,value,second,美妆,key From: https://www.cnblogs.com/wang715100018066/p/16625266.html