I have an object that looks like this:
const data = {
"supportPaneltext": [{
"brand": "BMW",
"paragraphList": [{
"rowList": [
"Europe, Middle East, Africa, Asia, Pacific"
]
}]
},
{
"brand": "Mercedez",
"paragraphList": [{
"rowList": [
"Europe, Middle East, Africa, Asia, Pacific"
]
}]
}]
}
I want to filter out the "brand" value to an array. The result would look like: ["BMW", Mercedez"]
I have tried to filter out by:
Object.values(data).filter((item) => item.brand)
Without luck, What do I miss?
You can use .map() on your supportPaneltext
let result = data.supportPaneltext.map(a => a.brand);
const data = {
"supportPaneltext": [{
"brand": "BMW",
"paragraphList": [{
"rowList": [
"Europe, Middle East, Africa, Asia, Pacific"
]
}]
},
{
"brand": "Mercedez",
"paragraphList": [{
"rowList": [
"Europe, Middle East, Africa, Asia, Pacific"
]
}]
}
]
}
let result = data.supportPaneltext.map(a => a.brand);
console.log(result);