NodeJS: How to remove duplicates from Array [duplicate] NodeJS: How to remove duplicates from Array [duplicate] arrays arrays

NodeJS: How to remove duplicates from Array [duplicate]


No, there is no built in method in node.js, however there are plenty of ways to do this in javascript. All you have to do is look around, as this has already been answered.

uniqueArray = myArray.filter(function(elem, pos) {    return myArray.indexOf(elem) == pos;})


No there is no built in method to get from array unique methods, but you could look at library called lodash which has such great methods _.uniq(array).

Also, propose alternative method as the Node.js has now support for Set's. Instead of using 3rd party module use a built-in alternative.

var array = [    1029,    1008,    1040,    1019,    1030,    1009,    1041,    1020,    1031,    1010,    1042,    1021,    1030,    1008,    1045,    1019,    1032,    1009,    1049,    1022,    1031,    1010,    1042,    1021,];var uSet = new Set(array);console.log([...uSet]); // Back to array