How to count unique value from object of array in javascript

后端 未结 4 1264
-上瘾入骨i
-上瘾入骨i 2021-01-21 13:34

I want to calculate number of unique value and put that in new array. I have below array:

[
  { CategoryId: \"b5c3f43f941c\", CategoryName: \"Category 1\", Categ         


        
4条回答
  •  粉色の甜心
    2021-01-21 13:59

    const array_unique = require('array-hyper-unique').array_unique
    
    let arr = [
      { CategoryId: "b5c3f43f941c", CategoryName: "Category 1", CategoryColor: "cgreen" }
      { CategoryId: "9872cce5af92", CategoryName: "Category 2", CategoryColor: "purple" }
      { CategoryId: "b5c3f43f941c", CategoryName: "Category 1", CategoryColor: "cgreen" }
    ]
    
    array_unique(arr).length
    

提交回复
热议问题