我有以下json数组:
int main()
{
std::string html = "<html>\n"\
"<header>" \
"<title>This is title</title></header>\n" \
"<body>\n"\
"Hello world\n"\
"</body>\n"\
"</html>";
html[1] = 'r';
std::cout<<html;
return 0;
}
如何使用javascript从中删除重复的值,所以最后我得到了:
["aa", "bb", "cc", "dd", "bb"]
答案 0 :(得分:2)
您可以使用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);
答案 1 :(得分:1)
console.log(_.uniq(["aa", "bb", "cc", "dd", "bb"]));
<script src="http://underscorejs.org/underscore-min.js"></script>