javascript - How to merge two arrays in Javascript and de-duplicate items
Development/JavaScript 2015. 8. 30. 17:08Q.
I have two JavaScript arrays:
var array1 = ["Vijendra","Singh"];
var array2 = ["Singh", "Shakya"];
I want the output to be:
var array3 = ["Vijendra","Singh","Shakya"];
The output array should have repeated words removed.
How do I merge two arrays in JavaScript so that I get only the unique items from each array in the same order they were inserted into the original arrays?
A.
This is simple and can be done in one line with jquery
var arr1 = ['Vijendra', 'Singh'], arr2 =['Singh', 'Shakya'];
$.unique(arr1.concat(arr2))//one line
["Vijendra", "Singh", "Shakya"]
source - http://stackoverflow.com/questions/1584370/how-to-merge-two-arrays-in-javascript-and-de-duplicate-items
'Development > JavaScript' 카테고리의 다른 글
javascript - IIFE, Module (0) | 2018.01.02 |
---|---|
javascript - Window self Property (0) | 2015.07.11 |
javaScript - Data Types (0) | 2015.07.11 |
javascript - How does this JavaScript/JQuery Syntax work: (function( window, undefined ) { })(window)? (0) | 2015.07.11 |
javascript - objects (0) | 2015.07.11 |