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

前端 未结 30 2616
执笔经年
执笔经年 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 05:57

    If this were PHP I'd build an array with the keys and take array_keys at the end, but JS has no such luxury. Instead, try this:

    var flags = [], output = [], l = array.length, i;
    for( i=0; i

提交回复
热议问题