get only the unique value of an array

后端 未结 5 1816
星月不相逢
星月不相逢 2021-01-14 09:16

I am new to javascript and I tried like using distinct but its not what im looking for

example array:

let arr = [ {key:\"1\",value:\"dog\"},
                 


        
5条回答
  •  爱一瞬间的悲伤
    2021-01-14 09:40

    Using the "find" method, you will get exactly what you are looking for "{key:"2",value:"cat"}".

    arr.find((item, index) => {
      const foundDup = arr.find((s, sIndex) => sIndex !== index && s.key === item.key);
      return !foundDup;
    });
    

提交回复
热议问题