根据指定id取出数组中指定对象

 // 需求:根据Id取出数组中指定的对象
  let arr =  [
      { id: 1, rotationAngle: 330, target: '目标1' },
      { id: 2, rotationAngle: 270, target: '目标2' },
      { id: 3, rotationAngle: 210, target: '目标三' },
  ]

  function getTargetObjById (id) {
    return arr.find(item => item.id === id)
  }
  
  console.log(getTargetObjById(2)) // { id: 2, rotationAngle: 270, target: '目标2' },
原文地址:https://www.cnblogs.com/xiaojuziya/p/12354173.html