'how to show an element in a object

i have an object in javascript. How can i only show "category = "hue" in console.log?

let colorlist = {
"colors": [
{
"color": "black",
"category": "hue", // only show this in console.log
"type": "primary",
"code": {
"rgba": [255,255,255,1],
"hex": "#000"
}
},
{
"color": "white",
"category": "value",
"code": {
"rgba": [0,0,0,1],
"hex": "#FFF"
}
},


Solution 1:[1]

You can do something like this

colorlist.colors.map((item) => {
    for (let [key, value] of Object.entries(item)) {
        if(value === "hue"){
            console.log(`"${key}" : "${value}"`);
        }
    }
})

The output will be

"category" : "hue"

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Rohìt Jíndal