w3resource logo

:

JavaScript Exercises

JavaScript: Remove duplicate items from an array, ignore case sensitivity

JavaScript Array: Exercise-14 with Solution

Write a JavaScript program to remove duplicate items from an array (ignore case sensitivity).

Sample Solution: -

HTML Code:

<!DOCTYPE html>
<html>
<head>
<meta charset=utf-8 />
<title>Remove duplicate items from an JavaScript array </title>
</head>
<body>
</body>
</html>

JavaScript Code:

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);

Flowchart:

Flowchart: JavaScript: Display the colors entered in an array by a specific format

Live Demo:

See the Pen JavaScript - Remove duplicate items from an array, ignore case sensitivity - array-ex- 14 by w3resource (@w3resource) on CodePen.


Improve this sample solution and post your code through Disqus