Now there is an attribute in the array. I want to delete this line of attributes when the value of this attribute is true, but how to delete all of them when there are multiple tru? now just delete one.

current array

    let arr = [
        {id:1,Itemtype:true,name:""},
        {id:2,Itemtype:false,name:""},
        {id:3,Itemtype:true,name:""},
        {id:4,Itemtype:false,name:""},
        {id:5,Itemtype:false,name:""},
        {id:6,Itemtype:true,name:""},
    ]
    

then I make a copy of this array

    var copy = [];
     for (var item in arr) {
            copy[item] = arr[item];
     }
         for(var i=0;i<copy.length;iPP){
                if(copy[i].Itemtype == true){
                    arrCopy.splice(i,1)//splicei,1true
                }
            }
            log(copy);

only one has been deleted, but how do I delete all the attributes whose value is true?

Oct.14,2021

arr.filter(({Itemtype})=>!Itemtype)

var copy = [];
 for (var item in arr) {
    if(!item.Itemtype){
        copy[item] = arr[item];
    }
 }

isn't this copy the deleted array?


just use filter, and the new array is returned.
arrCopy.splice (iPower1) this will change the length of the array, and there will be problems in the for loop


arr.filter ((item) = >! item.Itemtype)

Menu