I have two objects are contained by an array for each. The following code works. However, I am feeling this code I wrote is a bit odd. I am seeking a better or more standard way to improve below code. Thanks
const a = [
{
apple: '1',
banana: '2',
},
];
const b = [
{
apples: '1',
bananas: '2',
},
];
const json1 = JSON.parse(JSON.stringify(...a));
const json2 = JSON.parse(JSON.stringify(...b));
console.log({ ...{a: json1}, ...{b: json2}})
the output needs to be
{
"a": {
"apple": "1",
"banana": "2"
},
"b": {
"apples": "1",
"bananas": "2"
}
}
Edit: Sorry I forgot to mention previously, I don't want a[0]
b[0]