Files

25 lines
513 B
JavaScript
Raw Permalink Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
// find(callbackFn)
const stus = [
{ name: '张三', score: 59 },
{ name: '老钟', score: 95 },
{ name: 'SB', score: 80 }
];
// 筛选第一个 score >= 60 的信息
const rst = stus.find(item => { return item.score >= 60 })
console.log(rst)
// 浅表拷贝rst的修改会导致stus中对应数据的修改
rst.score = 100
console.log(stus)
/*
# node find.js
{ name: '老钟', score: 95 }
[
{ name: '张三', score: 59 },
{ name: '老钟', score: 100 },
{ name: 'SB', score: 80 }
]
*/