var userArray = [
{id:1,name:'gunsmoke1'},
{id:2,name:'gunsmoke2'},
{id:3,name:'gunsmoke3'},
{id:4,name:'gunsmoke4'},
];
var destUser = userArray.find((user) => {
return user.id == 1; //找到就直接退出,找不到则返回undefined
});
console.log(destUser); //{id: 1, name: "gunsmoke1"}
es6学习_数组方法_find
最新推荐文章于 2022-08-19 18:17:42 发布