📜  更改对象键名 javascript es6 - Javascript 代码示例

📅  最后修改于: 2022-03-11 15:02:39.109000             🧑  作者: Mango

代码示例2
const countries = [
    {"id": 1, "name": "Afghanistan"},
    {"id": 2, "name": "Albania"},
    {"id": 3, "name": "Algeria"},
    {"id": 4, "name": "American Samoa"}
];
const transformed = countries.map(({ id: label, name: value }) => ({ label, value }));
console.log(transformed);