JS Program to Remove Duplicates From Array
hannaA
Posted on July 30, 2022
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];
solution3
let array = ['1', '2', '3', '2', '3'];
let uniqueArray = [...new Set(array)];
console.log(uniqueArray);
💖 💪 🙅 🚩
hannaA
Posted on July 30, 2022
Join Our Newsletter. No Spam, Only the good stuff.
Sign up to receive the latest update from our blog.
Related
react Axios NPM Package: A Beginner's Guide to Installing and Making HTTP Requests
November 30, 2024