代码:
function removeByValue(arr, attr, value){ var index=-1; for(var i in arr){ if(arr[i][attr]==value){ index=i; break; } } if(index>-1){ arr.splice(index,1); } }
调用:
var arr=[{"uid":1,"name":"张三"},{"uid":2,"name":"李四"},{"uid":3,"name":"王五"}] removeByValue(arr,"uid",1);//删除对象里的uid是1的
微信扫码查看本文
发表评论