-3

I have the following json array:

["aa", "bb", "cc", "dd", "bb"]

How to remove the duplicate values from it with javascript, so at the end I got:

["aa", "bb", "cc", "dd"]
BoIde
  • 306
  • 1
  • 3
  • 16
  • https://stackoverflow.com/questions/9229645/remove-duplicate-values-from-js-array Try searching/googling before posting please. – Adam Aug 08 '18 at 12:52

2 Answers2

2

You can use Array.filter():

var arr = ["aa", "bb", "cc", "dd", "bb"];
var res = arr.filter(function(item, index){
  if(arr.lastIndexOf(item) === index){
    return true;
  }
}).sort(function(a, b){
  return a > b;
});
console.log(res);
Ankit Agarwal
  • 30,378
  • 5
  • 37
  • 62
1

console.log(_.uniq(["aa", "bb", "cc", "dd", "bb"]));
<script src="http://underscorejs.org/underscore-min.js"></script>
Sujan Gainju
  • 4,273
  • 2
  • 14
  • 34