JSON parsing is not working
So, I'm making a "shop" and the code in script.js shows how I'm going to be saving data, and I have some JSON in the third item of the array for storing the user's shopping cart, though when I want it to get the price of cattabby in the JSON, it gets "undefined". Any help?
Voters
RYANTADIPARTHI
The reason it is undefined is because it cannot happen. You can't do that. But if you are stringifying that, it probably will though. Stringing it.
realTronsi
You cannot JSON parse an array. If you try stringifying, you will see, as the name suggests, turns it into a string. Parsing will do the opposite, turn a string back to its original form.
realTronsi
@realTronsi could you also explain why you're trying to parse it? Doesn't make sense to me
Arrays start at index 0. You tried to access the fourth item, which is a boolean lol
Correct code:
Didn't work :/
@Coder100You stringified it so it became a string silly
@DabDatBassJust parse it directly
@DabDatBass