0
1

More than 1 year has passed since last update.

【JavaScript】配列内の連想配列の特定のキーの値の存在確認

Last updated at Posted at 2022-11-13

他に良い方法がありましたらご教示いただけますと幸いです。

const array = [{id:1},{id:2},{id:3}]
const check = (key,val) => array.find(obj => obj[key] === val) 

check("id",1)
>{id: 1}

check("id",4)
>undefined
0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1