Array.prototype.chooseSomeone = function(param, exeparam) {
let item
for (let i = 0; i < this.length; i++) {
if (this[i][param] == exeparam) {
item = this[i]
}
}
return item
}
//调用
let arr =[{id:3,name:"小胖娃娃"},{id:4,name:"小瘦娃娃"}]
arr.chooseSomeone("id",3) // {id:3,name:"小胖娃娃"}
JSON数组,封装根据属性查找数组对象的方法
猜你喜欢
转载自blog.csdn.net/zero_person_xianzi/article/details/88552204
今日推荐
周排行