0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

別の配列から重複しない値の配列を作り直したい

Last updated at Posted at 2022-01-11

配列A と配列Bにそれぞれ値があるが、配列Aに
含まれる値を
取り除いて配列Bを作り直したい

const list = [
  {
    id: 'f7747f80-9386-11eb-89b0',
  },
  {
    id: 'r7747f80-9386-11eb-89b0',
  }
];

const list2 = [
  {
     id: 'f7747f80-9386-11eb-89b0',
  },
  {
     id: 'a7747f80-9386-11eb-89b0',
  }
];


const targetList = list2.filter(o => !list.find(o => o.id === list2.id));

console.debug(1, targetList);

const allList = [...list, ...targetList]

console.debug(2, allList);

0
0
2

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
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?