更改数组中对象参数的名称

Cod*_*ker 1 javascript arrays object ecmascript-6

假设我有以下数组结构:

"stores" : [
    {
        id: 1,
        name: 'lopd',
    },
    {
        id: 2,
        name: 'abc'
    }
]
Run Code Online (Sandbox Code Playgroud)

我想将参数名称更改为以下内容:

"stores" : [
    {
        value: 1,
        label: 'lopd',
    },
    {
        value: 2,
        label: 'abc'
    }
]
Run Code Online (Sandbox Code Playgroud)

我将如何在 ES6 中做到这一点?

Nin*_*olz 5

您可以使用具有对象属性分配模式简写属性解构分配

var stores = [{ id: 1, name: 'lopd' }, { id: 2, name: 'abc' }];

stores = stores.map(({ id: value, name: label }) => ({ value, label }));

console.log(stores);
Run Code Online (Sandbox Code Playgroud)