Reputation: 105
I'm trying to target the "workdmark" result and the "description" result in the following JSON
{
"count": 1,
"trademarks": [{
"serialnumber": "85726321",
"wordmark": "RAIR",
"code": "GS0351",
"description": "Regulatory driver log audit reporting and vehicle accident
registry for the transportation industry",
"registrationdate": "06/25/2013"
}]
}
currently if I'm passing in "result", and I log
console.log(`${result.count}`);
I get 1 which is correct.
but if I
console.log(`${result.count}`);
console.log(`${result.trademarks}`);
console.log(`${result.trademarks.wordmark}`);
console.log(`${result.trademarks.description}`);
I get
1
[object object]
undefined
undefined
I thought I was targeting them correctly? What am I screwing up?
Upvotes: 0
Views: 58
Reputation: 54
If you see the structure of the trademark, basically it is an object in an array. So when you deal with these type of structure you should treat it as you are accessing an array and reference the index position first. Once you reference the index position you can then again use the object notation. So ideally you should do something like result.trademarks[0].wordmark
and you would get RAIR
.
Upvotes: 0
Reputation: 1224
You should get values as below
console.log(`${result.trademarks[0].wordmark}`);
console.log(`${result.trademarks[0].description}`);
Upvotes: 1