Q:

convert array of object to array of string - lodash

if i have the following array :
[
  {
    0:{
       id:5,
       name:'xxx'
      }
  },
  {
    1:{
       id:6,
       name:'yyy'
      }
  }
]

and i need to convert it to 
['xxx', 'yyy']

how to implement that with Lodash ?

A:

Here's a solution that makes use of lodash's flatMapDeep to extract the values before plucking the name:
let data = [
  {
    0:{
       id:5,
       name:'xxx'
      }
  },
  {
    1:{
       id:6,
       name:'yyy'
      }
  }
]

let result = _(data)
    .flatMapDeep(_.values)
    .map('name')
    .value()

Edit
Change the map to return a different value for each item. e.g to return the id and name as a key value pair you could do this:
let result = _(data)
    .flatMapDeep(_.values)
    .map( item => ({[item.id]: item.name}) )
    .value()

