Your Web News in One Place

Help Webnuz

Referal links:

Sign up for GreenGeeks web hosting
July 30, 2022 10:45 am GMT

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:    Share on Facebook
View Full Article

Dev To

An online community for sharing and discovering great ideas, having debates, and making friends

More About this Source Visit Dev To