首页 > 编程语言 > 详细

es6 find方法用于查找第一个符合条件的数组成员,如果没有找到返回undefind

时间:2020-04-25 18:04:08      阅读:155      评论:0      收藏:0      [点我收藏+]
<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>find方法</title>
</head>
<body>

</body>
<script>
    let arr = [
        {
            id:1,
            name:zhangsan
        },
        {
            id:2,
            name:lisi
        }
    ];

    //find方法用于查找第一个符合条件的数组成员,如果没有找到返回undefind
    let target = arr.find((item,index) => {
        return item.id ==1
    })
    console.log(target)
</script>
</html>

运行结果

技术分享图片

es6 find方法用于查找第一个符合条件的数组成员,如果没有找到返回undefind

原文:https://www.cnblogs.com/malong1992/p/12774115.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!