How to remove duplicate items from array in javascript?

Please share ways to remove duplicate items from array in JavaScript?

You can remove duplicate items from array in javascript using below methods:

1-  Using filter function:

var items = ["1", "2", "3", "1", "2", "4"];

var newArray = items.filter(function(item, index, items){

      return items.indexOf(item) === index }

);

 

2- Using core javascript logic:

function removeDuplicateItems(arr) { 

    var tempArr = {}; 

    for (var i = 0; i < arr.length; i++) 

        tempArr[arr[i]] = true; 

    return Object.keys(tempArr);

}

 

Both the ways can be used to remove duplicate items and use in your code solve the duplicacy problem.