Need to merge other country cities data into single object. my inputs are below
result = {
"Bangalore": [
{
"Type": "Sale",
"Date": "2021-07-10",
},
{
"Type": "Product",
"Date": "2021-07-03",
}
],
"Delhi": [
{
"Type": "Product",
"Date": "2021-06-30",
}
],
"Chennai": [
{
"Type": "Production",
"Date": "2021-06-30",
},
{
"Type": "Production",
"Date": "2021-07-11",
},
],
"Goa": [
{
"Type": "Product",
"Date": "2021-06-30",
}
],
"sydney": [
{
"Type": "Product",
"Date": "2021-06-30",
}
],
"melbourne": [
{
"Type": "Product",
"Date": "2021-06-30",
}
]
}
I have other country cities array is below
let arr = [
"sydney",
"melbourne"
]
I tried with below snippet its not working.
let {sydney,melbourne,...final}=result;
let othercity = [...sydney,...melbourne]
console.log(final)
Actually When I pass variable into let {sydney,melbourne,...final}
its working as expected. But I want to pass this variable sydney,melbourne
dynamically. ie 'let {...arr,...final}=result;'
Expected output results: IndiaCities
{
"Bangalore": [
{
"Type": "Sale",
"Date": "2021-07-10"
},
{
"Type": "Product",
"Date": "2021-07-03"
}
],
"Delhi": [
{
"Type": "Product",
"Date": "2021-06-30"
}
],
"Chennai": [
{
"Type": "Production",
"Date": "2021-06-30"
},
{
"Type": "Production",
"Date": "2021-07-11"
}
],
"Goa": [
{
"Type": "Product",
"Date": "2021-06-30"
}
]
}
otherCitys
{"othercities":[
{
"Type": "Product",
"Date": "2021-06-30"
},
{
"Type": "Product",
"Date": "2021-06-30"
}
]}
How to resolve this destructing concept. your answer is greatly appreciated
let result = {
"Bangalore": [
{
"Type": "Sale",
"Date": "2021-07-10",
},
{
"Type": "Product",
"Date": "2021-07-03",
}
],
"Delhi": [
{
"Type": "Product",
"Date": "2021-06-30",
}
],
"Chennai": [
{
"Type": "Production",
"Date": "2021-06-30",
},
{
"Type": "Production",
"Date": "2021-07-11",
},
],
"Goa": [
{
"Type": "Product",
"Date": "2021-06-30",
}
],
"sydney": [
{
"Type": "Product",
"Date": "2021-06-30",
}
],
"melbourne": [
{
"Type": "Product",
"Date": "2021-06-30",
}
]
}
let arr = [
"sydney",
"melbourne"
]
let {sydney,melbourne,...final}=result;
let othercity = [...sydney,...melbourne]
console.log(othercity)
console.log(final)