es6学习_数组方法_find

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"}
©️2020 CSDN 皮肤主题: 大白 设计师:CSDN官方博客 返回首页