是否了解find方法以在JavaScript中搜索特定记录?
要获取特定记录,请在一定条件下使用find()。
示例
以下是代码-
var obj=[
{
studentId:101,
studentName:"John"
},
{
studentId:102,
studentName:"Bob"
},
{
studentId:103,
studentName:"David"
}
]
const result = obj.find(
(o) =>
{
return o.studentId === 102
}
);
console.log(result);要运行上述程序,您需要使用以下命令-
node fileName.js.
在这里,我的文件名为demo315.js。
输出结果
这将产生以下输出-
PS C:\Users\Amit\javascript-code> node demo315.js
{ studentId: 102, studentName: 'Bob' }热门推荐
10 元旦的祝福语简短 公司
11 爸爸爱你祝福语大全简短
12 中秋送健康祝福语简短
13 考试祝福语日文简短版
14 青春告白祖国简短祝福语
15 开学新人祝福语简短英语
16 同学有弟弟祝福语简短
17 天气转凉祝福语简短
18 娶嫂子的祝福语简短