I have 2 arrays:
const notifications1 = [
{
id: "msg001",
profilePic: "https://randomuser.me/api/portraits/women/29.jpg",
platform: "instagram",
platformPic: "Instagram.png",
name: "Kimberly Connors",
content: "Great event! Looking forward to the next one!",
read: false,
dm: false,
},
{
id: "msg002",
profilePic: "https://randomuser.me/api/portraits/men/83.jpg",
platform: "instagram",
platformPic: "Instagram.png",
name: "Alex_Gamer92",
content: "Anyone up for a game night this weekend?",
read: false,
dm: true,
},
];
const notifications2 = [
{
id: "msg001",
profilePic: "https://randomuser.me/api/portraits/women/29.jpg",
platform: "instagram",
platformPic: "Instagram.png",
name: "Kimberly Connors",
content: "Great event! Looking forward to the next one!",
read: false,
dm: false,
},
{
id: "msg004",
profilePic: "https://randomuser.me/api/portraits/men/41.jpg",
platform: "instagram",
platformPic: "Instagram.png",
name: "John Doe",
content: "Count me in too!",
read: false,
dm: false,
},
];
How do I merge them to have only the ones with similar values like this:
const notificationsMerge = [
{
id: "msg001",
profilePic: "https://randomuser.me/api/portraits/women/29.jpg",
platform: "instagram",
platformPic: "src/assets/Instagram_Glyph_Gradient.png",
name: "Kimberly Connors",
content: "Great event! Looking forward to the next one!",
read: false,
dm: false,
},
];
Right now, I’m only focused on the dm and platform similarities, but if I can learn how to do 1, the rest shouldn’t be too hard.
The only way I’ve seen so far is
const notificationsMerge = [...notifications1, ...notifications2]
but this merges everything. Anyways, thanks in advance for any help or directions to any documents.
New contributor
Brandon Aguilar is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.