(编辑:jimmy 日期: 2024/10/30 浏览:2)
删除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); } };
jquery判断数组中是否含有某个元素
$.inArray(‘1',objArray) //返回‘1'的索引,如果不存在则返回-1
js数组删除元素、json删除元素
//数组var b=[1,2,3,4]; b.splice(b.indexOf(2,1)) //1,3,4 //json var arrayId=[{"id":233,"name":"英语"},{"id":122,"name":"语文"},{"id":10,"name":"数学"}] for(var i=0;i<arrayId.length;i++){ if (arrayId[i].id == item.id){//item.id==122 arrayId.splice(i,1) } } //{"id":233,"name":"英语"},{"id":10,"name":"数学"}