Remove duplicates from array in Javascript | Algorithm Interview Question
The filter() method creates a new array and populates that array with all the elements that meet the condition specified in a callback function. The filter method calls the callback function one time for each element in the array. If the callback function returns false for all elements of the array, the length of the new array that will be returned is 0.
/***************************/
let jsArray = ["amit","maithili","aayush","amit","maithili","ramesh","suresh"];
let uniqueArray = jsArray.filter(function(value,index,array){
return array.indexOf(value) == index
});
console.log(`[${uniqueArray}]`);
/***************************/
Music: "Royalty free music from Bensound"
You can donate 💰💰 at paypal.me/devamitjha
#devamitjha #javascript #filtermethod #interviewQuestion