Deleting an element from JSON data

There is a set of JSON data:

var tempJSON = [{id:1,Name:"peter"},{id:2,Name:"James"},{id:3,Name:"Other"}];

when passing in ids The value of [1,2] is how JS deletes the data with id 1,2 in the tempJSON array, and the final result is:

tempJSON=[{id:3,Name:"Other"}]

The workaround is as follows:

var  tempJSON = [{id:1,Name: "peter" },{id:2,Name: "James" },{id:3,Name: "Other" }];
var  newArr =  new  Array();
for ( var  i=0;i< tempJSON.length;i++){
var  j=tempJSON[i];
if (j.id!=1&&j.id!=2){
newArr.push(j);
}
}
console.info(newArr);

 

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326464796&siteId=291194637
Recommended