I have such an object.
let Filus = {
male: {
hat: [1],
jacket: [2],
pants: [3],
shoes: [4],
suit: [5]
}
};
I want to get this array from this object.
let Filus = [1,2,3,4,5];
How to do it?
You can get values of nested object male using Object.values() and then use flat()
let Filus = { male : { hat: [1], jacket: [2], pants: [3], shoes: [4], suit: [5] } };
const res = Object.values(Filus.male).flat();
console.log(res)
You can also do that without flat() using concat() and spread operator.
let Filus = { male : { hat: [1], jacket: [2], pants: [3], shoes: [4], suit: [5] } };
const res = [].concat(...Object.values(Filus.male));
console.log(res)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With