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"]
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"]
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);
console.log(_.uniq(["aa", "bb", "cc", "dd", "bb"]));
<script src="http://underscorejs.org/underscore-min.js"></script>