array.find()遍历数组
find方法:返回数组第一个满足条件的元素
array.find ( function( item , index , arr ) {
})
find的使用场景:返回数组第一个大于60的值。返回数组第一个等于‘陈卓’的值
例如:取出 id 为 1 的对象
const books = [{
"id": 1, //图书id
"bookname": "西游记", //书名
"author": "吴承恩", //作者
"publisher": "北京出版社" //出版社
}, {
"id": 2, //图书id
"bookname": "红楼梦", //书名
"author": "曹雪芹", //作者
"publisher": "大清出版社" //出版社
}]
const ret = books.find(item => item.id === 1)//遍历books数组,获取第一个id等于1的值
console.log(ret);
const ret = books.find(item => item.id === 1)中
find方法中只能填写函数