Mok*_*umJ -3 javascript functional-programming
我在函数式编程游戏中有点迷失.
我有一个像这样的对象:
const answers = {1: 'first', 2:'second', 3:'third', 4:'fourth'}Run Code Online (Sandbox Code Playgroud)
我想将对象重塑为像这样的对象数组.
const arrayOfAnswers = [{1:'first'}, {2:'second'}, {3:'third'}, {4:'fourth'}]Run Code Online (Sandbox Code Playgroud)
达到此目的的简单解决方案是什么?
您可以使用销毁键/值进行映射.
var answers = { 1: 'first', 2: 'second', 3: 'third', 4: 'fourth' },
array = Object.entries(answers).map(([k, v]) => ({ [k]: v }));
console.log(array);Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
69 次 |
| 最近记录: |