How can I loop through arrays inside an object in JavaScript es6? I tried the following code
for(let x of Object.keys(headings?.value)){
console.log(x);
}
data i wants to loop through
"value":{
"h3":[
"Best selling products",
"Best Corporate Laptops",
"BEST PRICED LAPTOPS",
"Shop By Brands"
],
"h4":[
"Lenovo Thinkpad Touchscreen Yoga X380\/i5\/8th gen\/13.3\" screen",
"Lenovo thinkpad T440S\/core i7\/4th gen\/14\"screen"
],
"h5":[
"View All",
]
}
Object.values().flat()instead ofObject.keys(). Also, you don't need?.; just useheadings.value. Ifheadingsis nullishObject.keys()/.values()will throw an error anyway.