My Object contains different datatypes including array. I want to concatenate all arrays(in a single array) I have written using foreach and concat.
Is there any way I can have a better solution, or this is correct?
See the below snippet. concat array value3 and value5 into single array.
var Input = {
"value1": 10,
"value2": "abcd",
"value3": [
{
"v1": 100,
"v2": 89
},
{
"v1": 454,
"v2": 100
}
],
"value4": "xyz",
"value5": [
{
"v6": 1,
"v7": -8
},
{
"v1": 890,
"v2": 10
}
]
}
var OutputData = [];
let keys = Object.keys(Input);
keys.forEach(key => {
if (Array.isArray(Input[key])) {
try {
OutputData= OutputData.concat(Input[key])
} catch (error) {
}
}
});
console.log(OutputData)