EN
JavaScript - object destructuring and renaming property
1 answers
0 points
Let's say I have the following object:
xxxxxxxxxx
1
const a = {
2
b: {
3
c: 'value'
4
}
5
};
Now, I want get c
and also rename b
property. Is it possible?
1 answer
0 points
You can take destructure object renaming the property and take the same property for destructuring, like this:
xxxxxxxxxx
1
const a = {
2
b: {
3
c: 'value'
4
}
5
};
6
7
const { b: newName, b: { c } } = a;
8
9
console.log(JSON.stringify(newName)); // {"c":"value"}
10
console.log(c); // value
0 commentsShow commentsAdd comment