dimanche 9 octobre 2016

How I can iterate over a nested object and create another object which is like this object in some properties?

I have an object as bellow:

objBase = {
  name: { 
    type : 'string',
    defaultVal: 'Jack'
  },
  reservations: {
    rooms: [ 
      { date: '2016-09-08, no: 200 },
      { date: '2016-09-21', no: 300 }
    ],
    nested: {
      date: '2016-09'
      type: 'hotel'
    }
  }
}

now I need to mine some property from pre object and save in another object which should be as bellow:

newObj = {
  name: 'Jack'
  reservations: {
      date: '2016-09'
  }
}

we have nested and defaultVal in all objects but other properties may be different so we just want to remove all nested and some other properties.nested may have nested also How I can achieve this with best performance?

Aucun commentaire:

Enregistrer un commentaire