Skip to main content
Active reading.
Source Link
Peter Mortensen
  • 31.3k
  • 22
  • 109
  • 132

You can do it simply with ES6ECMAScript 6,

var array1 = ["Vijendra", "Singh"];
var array2 = ["Singh", "Shakya"];
var array3 = [...new Set([...array1 ,...array2])];
console.log(array3); // ["Vijendra", "Singh", "Shakya"];
  • Use the spread operator for concatenating the array.
  • Use Set for creating a distinct set of elements.
  • Again use the spread operator to convert the Set into an array.

You can do it simply with ES6,

var array1 = ["Vijendra","Singh"];
var array2 = ["Singh", "Shakya"];
var array3 = [...new Set([...array1 ,...array2])];
console.log(array3); //["Vijendra","Singh","Shakya"];
  • Use spread operator for concatenating the array.
  • Use Set for creating a distinct set of elements.
  • Again use spread operator to convert the Set into an array.

You can do it simply with ECMAScript 6,

var array1 = ["Vijendra", "Singh"];
var array2 = ["Singh", "Shakya"];
var array3 = [...new Set([...array1 ,...array2])];
console.log(array3); // ["Vijendra", "Singh", "Shakya"];
  • Use the spread operator for concatenating the array.
  • Use Set for creating a distinct set of elements.
  • Again use the spread operator to convert the Set into an array.
Source Link

You can do it simply with ES6,

var array1 = ["Vijendra","Singh"];
var array2 = ["Singh", "Shakya"];
var array3 = [...new Set([...array1 ,...array2])];
console.log(array3); //["Vijendra","Singh","Shakya"];
  • Use spread operator for concatenating the array.
  • Use Set for creating a distinct set of elements.
  • Again use spread operator to convert the Set into an array.