Reputation: 657
I've saved a json response as a global object variable in chrome console (chrome stored as temp1), set an object property of that as fieldsObj1 below:
>> var fieldsObj1 = temp1.fields;
This command in chrome console diplays a tree view of the fieldsObj1 properties, which I have expanded and pasted below, leaving the relevant 'undefined' property: contentAll.full.
>> fieldsObj1
Object {contentText.split: Array[12], metricsListed: Array[1], sourceDescription: Array[1], sourceCode: Array[1], geoLocation: Array[1]…}
_rev: Array[1]
coded.matchedIn: Array[3]
[...many alphabetized properties skipped here]...until we get to relevant contentAll.full below
contentAll.full: Array[1]
0: "Just updated my blog. Check it out! In Spite of Threats, Parents, States and Teachers are Dumping Common Core http://t.co/wlxofg2G2K #tcot"
length: 1
__proto__: Array[0]
[...more properties listed in chrome console object tree...]
contentAll.full displays in the chrome tree object viewer as an 'Array[1]', with the array item being the text data I am trying to store to a local variable.
However, the following commands indicate the array item is inaccessible due to the containing object ,fieldsObj1.contentAll, being undefined.
fieldsObj1.contentAll.full[0]
TypeError: Cannot read property 'full' of undefined
fieldsObj1.contentAll.full
TypeError: Cannot read property 'full' of undefined
fieldsObj1.contentAll
undefined
How is it undefined, when I can see it in the chrome tree view?
How can I save that seemingly-inaccessible data to a local variable?
Upvotes: 0
Views: 300
Reputation: 223
fieldsObj1.contentAll.full[0]
is different than
fieldsObj1['contentAll.full'][0]
The sqare bracket notation allows you to define object keys more freely. As you can see, there is a property on your fieldsObj1
called 'contentAll.full', but defining such property is not equivalent to creating fieldsObj1.contentAll
object and defining a property full
there.
Upvotes: 2