java script array

Report
Question

Please briefly explain why you feel this question should be reported .

Report
Cancel

how we will delete duplicates in an array in java script by using only loops and conditional statements.

in progress 0
JavaScript 3 months 1 Answer 3291 views 0

Answer ( 1 )

  1. rg123

    Please briefly explain why you feel this answer should be reported .

    Report
    Cancel
    function removeDuplicates(num) {
      var x,
          len=num.length,
          out=[],
          obj={};
     
      for (x=0; x<len; x++) {
        obj[num[x]]=0;
      }
      for (x in obj) {
        out.push(x);
      }
      return out;
    }
    var Mynum = [1, 2, 2, 4, 5, 4, 7, 8, 7, 3, 6];
    result = removeDuplicates(Mynum);
    console.log(Mynum);
    console.log(result);
    

    For more details visit: http://www.w3resource.com/javascript-exercises/javascript-array-exercise-14.php

Leave an answer

Browse

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>