This is my object data:
[{id:1, name:"Cat", category:{id:2, name:"Animals"}}]
I want to check if it contains the key category.
This is my approach:
if (data.hasOwnProperty("category")) {
console.log("data contains category");
}else {
console.log("data does not contain category");
}
The output is:
data does not contain category
Should be the opposite...
data.alert(data.toString());this is the ouput:[object Object],[object Object],[object Object],[object Object],[object Object],[object Object],[object Object][ ]around an object; it's an array with one object in it.