This is a JSON string:
'["Ford", "BMW", "Fiat"]'
Inside the JSON string there is a JSON array literal:
["Ford", "BMW", "Fiat"]
Arrays in JSON are almost the same as arrays in JavaScript.
In JSON, array values must be of type string, number, object, array, boolean or null.
In JavaScript, array values can be all of the above, plus any other valid JavaScript expression, including functions, dates, and undefined.
You can create a JavaScript array from a literal:
You can create a JavaScript array by parsing a JSON string:
You access array values by index:
Objects can contain arrays:
{
"name":"John",
"age":30,
"cars":["Ford", "BMW", "Fiat"]
}
You access array values by index:
You can access array values by using a for in
loop:
Or you can use a for
loop:
截取页面反馈部分,让我们更快修复内容!也可以直接跳过填写反馈内容!