How to rename key in object?

0 like 0 dislike
3 views
there is an object:
{ "id": ", "name":" }
need to do =>
{ "value": ", "label":" }


I have written so
computed: { ...mapState({ categories: state => state.main_page.NEWS }), getCategories() { let arr = []; let categories = this.categories; categories.forEach(function(obj) { obj['value'] = obj['id']; obj['label'] = obj['name']; delete obj['id']; delete obj['name']; arr.push(obj) }) return arr } }


everything works. but he changed this.categories
How to make the original source was the old name of the keys created with new?
by | 3 views

1 Answer

0 like 0 dislike
getCategories() { return this.categories.map(n => ({ value: n.id label: n.name })) }
by

Related questions

0 like 0 dislike
1 answer
0 like 0 dislike
1 answer
0 like 0 dislike
2 answers
0 like 0 dislike
1 answer
110,608 questions
257,186 answers
0 comments
33,904 users