transform object to array with lodash

siavolt picture siavolt · Jul 10, 2014 · Viewed 193.2k times · Source

How can I transform a big object to array with lodash?

var obj = {
  22: {name:"John", id:22, friends:[5,31,55], works:{books:[], films:[],}
  12: {name:"Ivan", id:12, friends:[2,44,12], works:{books:[], films:[],}
}

// transform to 
var arr = [{name:"John", id:22...},{name:"Ivan", id:12...}]

Answer

Daniel Schmidt picture Daniel Schmidt · Jul 10, 2014

You can do

var arr = _.values(obj);

For documentation see here.