change object key name javascript es6

Solutions on MaxInterview for change object key name javascript es6 by the best coders in the world

showing results for - "change object key name javascript es6"
Lennart
06 Jul 2018
1const countries = [
2    {"id": 1, "name": "Afghanistan"},
3    {"id": 2, "name": "Albania"},
4    {"id": 3, "name": "Algeria"},
5    {"id": 4, "name": "American Samoa"}
6];
7const transformed = countries.map(({ id, name }) => ({ label: id, value: name }));
8console.log(transformed);
Nicole
13 Oct 2019
1const countries = [
2    {"id": 1, "name": "Afghanistan"},
3    {"id": 2, "name": "Albania"},
4    {"id": 3, "name": "Algeria"},
5    {"id": 4, "name": "American Samoa"}
6];
7const transformed = countries.map(({ id: label, name: value }) => ({ label, value }));
8console.log(transformed);