objects [ {
firstName: "Kristian",
lastName: "Vos",
number: "unknown",
likes: ["JavaScript", "Gaming", "Foxes"],
}….]
if this is my object, i need to read the word "firstName" and not the value of "firstName"
i know how to output the value of firstName ( objects[0].fisrtName ) = "Kristian"
but what i really need to read is if the object has a property called firstName, in case that the object doesnt have that property.
thanks
>Solution :
I think you code isn’t actually object since you use [ ], it is more likely an array contain object.
This code should work, if you mistype the [ ], just use Object.keys(test)[0] instead.
let test = [{
firstName: "Kristian",
lastName: "Vos",
number: "unknown",
likes: ["JavaScript", "Gaming", "Foxes"]
}]
console.log(Object.keys(test[0])[0])