根據指定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' },

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM