How to make object which store unique key have multiple different values

    var data = [{type: 'physical', value: 'verified'}, 
                {type: 'reference', value: 'owner'},
                {type: 'physical', value: 'pending'},
                {type: 'document', value: 'pending'}

How to return object in such a way which should have unique key which store mulpltiple values

Expected Result =

  var data  = {
      physical: ['verified', 'pending'],
      reference: ['owner'],
      document: ['pending']

>Solution :

this function should return the result as you asked.

function getUnique(data){
    let x = {};
    for(let i of data){
        if (!x[i.type]){x[i.type] = [];}
    return x;

Leave a Reply