An Interest In:
Web News this Week
- April 19, 2024
- April 18, 2024
- April 17, 2024
- April 16, 2024
- April 15, 2024
- April 14, 2024
- April 13, 2024
July 30, 2022 10:45 am GMT
Original Link: https://dev.to/hannaha88/js-program-to-remove-duplicates-from-array-56hi
JS Program to Remove Duplicates From Array
solution1
let array = ['1', '2', '3', '2', '3'];let uniqueArray = [];array.forEach((c) => { if (!uniqueArray.includes(c)) { uniqueArray.push(c); }});console.log(uniqueArray);
solution2
function getUnique(arr){ let uniqueArr = []; //loop through array for(let i of arr) { if(uniqueArr.indexOf(i) === -1) { uniqueArr.push(i); } } console.log(uniqueArr);}const array = [1,2,3,2,3];
Original Link: https://dev.to/hannaha88/js-program-to-remove-duplicates-from-array-56hi
Share this article:
Tweet
View Full Article
Dev To
An online community for sharing and discovering great ideas, having debates, and making friendsMore About this Source Visit Dev To