lodash - project/transform object into key value array

前端 未结 6 693
没有蜡笔的小新
没有蜡笔的小新 2020-12-05 13:10

I\'m about to use forOwn to iterate through an object\'s properties and create an array manually and can\'t helping thinking there\'s a oneliner already availab

6条回答
  •  [愿得一人]
    2020-12-05 14:07

    In response to Ori's comment and for completeness, I've posted the _.forOwn version. It's marginally faster but you need to declare the array first (not-a-one-liner).

    var arr = [];
    _.forOwn(obj,function(item, key) {
        arr.push({ property : key, value : item});
    });
    

提交回复
热议问题