Answers for "javascript merge two arrays of objects without duplicates"

1

javascript merge arrays of objects without duplicates

var merged = [...initialData, ...newData.filter(d => !ids.has(d.ID))];
Posted by: Guest on February-19-2021
0

javascript merge two arrays of objects without duplicates

var initialData = [{
    'ID': 1,
    'FirstName': 'Sally'
  },
  {
    'ID': 2,
    'FirstName': 'Jim'
  },
  {
    'ID': 3,
    'FirstName': 'Bob'
  }
];

var newData = [{
    'ID': 2,
    'FirstName': 'Jim'
  },
  {
    'ID': 4,
    'FirstName': 'Tom'
  },
  {
    'ID': 5,
    'FirstName': 'George'
  }
];

var ids = new Set(initialData.map(d => d.ID));
var merged = [...initialData, ...newData.filter(d => !ids.has(d.ID))];
Posted by: Guest on July-09-2021
0

merge array no duiplicates js

let array1 = ['a','b','c'];
let array2 = ['c','c','d','e'];
let array3 = array1.concat(array2);
array3 = [...new Set([...array1,...array2])]; // O(n)
Posted by: Guest on December-04-2020
0

how to add to array in single without repetation

result[0] = 11
result[1] = 22
result[2] = 33
result[3] = 11, 22
result[4] = 11, 33
result[5] = 22, 11
result[6] = 22, 33
result[7] = 33, 11
result[8] = 33, 22
result[9] = 11, 22, 33
result[10] = 11, 33, 22
result[11] = 22, 11, 33
result[12] = 22, 33, 11
And so on... (It's not necessary to have that order, i just want every possible variation (without repeating the same value on the index) on another array)
Posted by: Guest on October-24-2020

Code answers related to "javascript merge two arrays of objects without duplicates"

Code answers related to "Javascript"

Browse Popular Code Answers by Language