transform object to array with lodash

后端 未结 11 1467
旧时难觅i
旧时难觅i 2020-12-22 23:38

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

var obj = {
  22: {name:\"John\", id:22, friends:[5,31,55], works:{books:[],         


        
11条回答
  •  北海茫月
    2020-12-23 00:04

    For me, this worked:

    _.map(_.toPairs(data), d => _.fromPairs([d]));
    

    It turns

    {"a":"b", "c":"d", "e":"f"} 
    

    into

    [{"a":"b"}, {"c":"d"}, {"e":"f"}]
    

提交回复
热议问题