JSFiddle - React, Tailwind, and code Playground
by JinHan Heo
JavaScript
const comments=[
{ id:1, body: '안녕하세요1',},
{ id:2, body: '안녕하세요2', },
{ id:3, body: '안녕하세요3',}
];
const newComments=[
{ id:1, body:"10101010101010",},
{ id:999, body:"aaa"}
];
const keys = comments.map(v => v.id)
const uniqueComments = newComments.filter(v => !keys.includes(v.id)).concat(...comments).sort((a, b) => a.id - b.id)
console.log(uniqueComments)