I need the value of keys in object arrA
to be copied from arrB
based on key
name. Here are my two objects:
let arrA = {
'aaa':'',
'bbb':'',
'ccc':''
}
let arrb = {
'aaa':'111',
'bbb':'222',
'ccc':'333',
'ddd':'444',
'eee':'555',
...
}
How do I do this with the ES6
deconstructive assignment:
arrA = {
'aaa':'111',
'bbb':'222',
'ccc':'333'
}
Using destructing assignment, you'd have to explicitly define each property you'd want to copy:
let arra = {
'aaa': '',
'bbb': '',
'ccc': ''
};
let arrb = {
'aaa': '111',
'bbb': '222',
'ccc': '333',
'ddd': '444',
'eee': '555',
};
({aaa: arra.aaa, bbb: arra.bbb, ccc: arra.ccc} = arrb);
console.log(arra);
However, this code is very repetitive, and the worst part is that it's explicit with what gets copied.
Collected from the Internet
Please contact [email protected] to delete if infringement.
Comments