JS new set, remove duplicates case insensitive?

前端 未结 3 1623
醉梦人生
醉梦人生 2021-01-06 03:17
var arr = [\'verdana\', \'Verdana\', 2, 4, 2, 8, 7, 3, 6];
result =  Array.from(new Set(arr));

console.log(arr);
console.log(result);

i want to re

3条回答
  •  一生所求
    2021-01-06 04:22

    You can use Set after converting the string elements to uppercase.Here ... is spread operator

    var arr = ['verdana', 'Verdana', 2, 4, 2, 8, 7, 3, 6];
    
    var result = arr.map(function(item) {
      return typeof item === "string" ? item.toString().toUpperCase() : item
    })
    
    result = [...new Set(result)];
    
    console.log(result);

提交回复
热议问题