Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR JAVASCRIPT

get unique numbers of an array in javascript using for loop

var array = [3,7,5,3,2,5,2,7];

for(var i=0;i<array.length;i++) {
    for(var j=i+1;j<array.length;j++) {
        if(array[i]===array[j]) {
            array.splice(j,1);
        }
    }
}
console.log(array); // output = [3,7,5,2]
 Run code snippet
Source by stackoverflow.com #
 
PREVIOUS NEXT
Tagged: #unique #numbers #array #javascript #loop
ADD COMMENT
Topic
Name
2+6 =