js json中如何删除指定元素

如题所述

第1个回答  2018-11-15
删除json下指定的元素
var obj = {‘id’:1, ‘name’:2};
delete obj.id;
delete obj[id];
console.log(obj); // {‘name’:2}

删除数组中指定元素
var objArray = [‘1’,’2’,’3’,’4’];
objArray.remove(‘1’);
console.log(objArray); // [‘2’,’3’,’4’]
/*定义js数组删除元素/
Array.prototype.remove = function(val) {
var index = this.indexOf(val);
if (index > -1) {
this.splice(index, 1);
}
};本回答被网友采纳

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网