他に良い方法がありましたらご教示いただけますと幸いです。
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
Go to list of users who liked
More than 1 year has passed since last update.
他に良い方法がありましたらご教示いただけますと幸いです。
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
Register as a new user and use Qiita more conveniently
Go to list of users who liked