How to merge two arrays in javascript and have unique values
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
function merge_array(array1, array2) { var result_array = []; var arr = array1.concat(array2); var len = arr.length; var assoc = {}; while(len--) { var item = arr[len]; if(!assoc[item]) { result_array.unshift(item); assoc[item] = true; } } return result_array; } |
Source: https://www.w3resource.com/javascript-exercises/javascript-array-exercise-30.php