LoginSignup
1
0

More than 3 years have passed since last update.

連想配列同士でfilterし新しく連想配列を作る

Last updated at Posted at 2020-04-27

コード

sample
   let fruits = [
                { id: 1, name: 'apple' },
                { id: 2, name: 'banana' },
                { id: 3, name: 'orange' },
                { id: 4, name: 'berry' }
            ]

   let target = [
                { fruits_id: 1, name: 'apple' },
                { fruits_id: 4, name: 'berry' }
            ]

   console.log(fruits.filter(x => !target.map(t => t.fruits_id).includes(x.id)))

参考

【JavaScript】filterとincludesで配列のデータを抽出

1
0
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
1
0