'In angular Typescript, when logging a structure it looks correct, but when logging a member in it, it gets undefined
I have the following "prod" structure (from log):
cat_id: "1"
category: "2"
description: "The Nike Zoom Pegasus Turbo 2 is updated with a feather-light upper, while innovative foam brings revolutionary responsiveness to your long-distance training"
id: "2"
image: "https://i.pinimg.com/originals/43/40/8e/43408ee5a8d234752ecf80bbc3832e65.jpg"
images: "https://i.pinimg.com/originals/43/40/8e/43408ee5a8d234752ecf80bbc3832e65.jpg;https://i.ebayimg.com/images/g/eQgAAOSw2XdePfc0/s-l640.jpg;https://i.ebayimg.com/images/g/j~gAAOSwQ6FdG9Eh/s-l640.jpg;https://i.ebayimg.com/images/g/OesAAOSwDnpeJhWN/s-l640.jpg"
price: "59.99"
quantity: "51"
short_desc: "SPORTS SHOES"
title: "Electronics"
but, when logging, I am getting the following results:
console.log(prod)
-> correct, getting the above structure
console.log(prod.images)
-> undefined
Any suggestion? Thanks
Solution 1:[1]
Do something instead of doing console log on prod do
console.log(JSON.stringify(prod))
.
I am sure you won't see images property in it. Actually objects work on reference, when its printed in console directly, it keeps refering to same reference. So once you expand it it refers to same reference and shows the value. You just have to make sure that prod have images property before using the property.
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Aakash Garg |