Answer the question
In order to leave comments, you need to log in
How to work with arrays?
When I write alert(data)
, the alert displays
[{"id":84,"img_name":"o1.jfif","product_id":43,"title":"","alt":"","color_name":"Black"},{"id":85,"img_name":"o2.jfif","product_id":43,"title":"","alt":"","color_name":"OrangeRed"}]
alert(data[0])
then the alert displays [
alert(data[0].id)
then the alert displays undefined
Answer the question
In order to leave comments, you need to log in
Well, you have a string in data, not an array. This is a JSON string, convert it to an array.
let dataArr = JSON.parse(data);
alert(dataArr[0]);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question