I have this following object:
{
12232: [],
34232: [],
23435: []
}
I want to extract the keys from this object to show them as labels in my React frontend. How can I accomplish this?
I have this following object:
{
12232: [],
34232: [],
23435: []
}
I want to extract the keys from this object to show them as labels in my React frontend. How can I accomplish this?
Use JS built-in Object.keys()
for that.
const myObject = {
12232: [],
34232: [],
23435: []
};
const keys = Object.keys(myObject);
keys.forEach(key => {
console.log(key);
});
You could use Object.keys
to extract the keys out of your object.
You could check the docs of Object.keys
here
const obj = {
12232 : [],
34232 : [],
23435: []
}
Object.keys(obj); // returns ['12232', '34232', '23435'];