The difference between JSON and array

Source: Internet
Author: User

JSON is a data format in JavaScript that resembles an array, but differs from an array in that it differs from the subscript :

For example, Var obj=[a:15,b:10,c:3,d:8];//This is the notation for JSON

var arr=[15,10,3,8]; This is the notation of the array

As can be seen, each element in the JSON is a string as subscript: A,b,c,d, and the array is a number as subscript, 0,1,2,3

There are two methods of array looping :

1) Normal for loop

2) for in:

var i=0;

For (i in arr) {.... }

For arrays, the for loop is more flexible because it can change the position of the starting loop, such as i=1,2,3, and the For in loop cannot be changed, but can be looped from beginning to end,

json loop method : Just can use the for

such as: for (i in obj) {... }

The difference between JSON and array

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.