findINdex遍历数组对象返回索引

findINdex()遍历数组里的对象返回索引,
注意,只能遍历数组里面的对象
不匹配返回-1

  // findINdex遍历数组返回数组第一个索引,
      const i = list.findIndex(item => item.id === 1)
   返回1,当中的item一定要是对象,要不然返回-1
list:
[
  {
    "id": 0,
    "info": "Racing car sprays burning fuel into crowd.",
    "done": true
  },
  {
    "id": 1,
    "info": "Japanese princess to wed commoner.",
    "done": false
  }
]

你可能感兴趣的:(数组,对象)