javascript - lodash分配键值对

标签 javascript node.js lodash vuejs2

如何改变这个

[ { '1491926400000': 222 }, { '1491926400000': 489 } ]

对此:

[ { date: '1491926400000', count: 222 }, { date: '1491926400000', count: 489 } ]

我尝试过使用 lodash 进行“减少”和“转换”,但没有任何效果。

最佳答案

使用Array#map的可能解决方案。

var arr = [{ '1491926400000': 222 }, { '1491926400000': 489 }],
    res = arr.map(v => Object.assign({}, ...Object.keys(v).map(c => ({ date: c, count: v[c]}))));
    
    console.log(res);

关于javascript - lodash分配键值对,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43354430/

相关文章:

Javascript:如何通过指定字符串中的字段来创建对象?

javascript - 通过过滤连接两个数组

javascript - 在 lodash 中将 _.set 与 _.each 一起应用

javascript - 在 QML 中解析 JSON

javascript - 如何使用 Material-UI 将多个 TextField 元素放入 Grid 容器中?

javascript - 链接标记在 Ember Js 中不起作用

javascript - 使用 LoDash 或类似工具规范化/展平 JS 数组?

javascript - 从 javascript 自动化 Windows 2007 的 Word

angularjs - 下载从nodejs传递到前端angularjs的xlsx文件

c++ - Node 插件编译错误