How to get distinct values from an array of objects in JavaScript?

前端 未结 30 3110
执笔经年
执笔经年 2020-11-22 05:29

Assuming I have the following:

var array = 
    [
        {\"name\":\"Joe\", \"age\":17}, 
        {\"name\":\"Bob\", \"age\":17}, 
        {\"name\":\"Carl\         


        
30条回答
  •  温柔的废话
    2020-11-22 06:04

    This is how you would solve this using new Set via ES6 for Typescript as of August 25th, 2017

    Array.from(new Set(yourArray.map((item: any) => item.id)))
    

提交回复
热议问题