其他分享
首页 > 其他分享> > js简写

js简写

作者:互联网

在数组中查找对象

要通过其中一个属性从对象数组中查找对象的话,我们通常使用for循环:

let inventory = [
  {name: 'Bananas', quantity: 5},
  {name: 'Apples', quantity: 10},
  {name: 'Grapes', quantity: 2}
];

// Get the object with the name `Apples` inside the array
function getApples(arr, value) {
  for (let index = 0; index < arr.length; index++) {

    // Check the value of this object property `name` is same as 'Apples'
    if (arr[index].name === 'Apples') {  //=> 

标签:USER,arr,name,js,role,userRole,简写,Apples
来源: https://www.cnblogs.com/baller-coder/p/16452065.html