Difference between "var arr = [];" and "var arr = {};", and vararr

Source: Internet
Author: User

Difference between "var arr = [];" and "var arr = {};", and vararr

1. Interview Questions

Var arr = [];

Var arr = {};

What is the difference between the above Code?


2. Analysis

Var arr = []; is an array object

Var arr ={}; is an object


In JS, var arr = retsplit ("\ 7"); what does "\ 7" represent?

For example:
<Script type = "text/javascript">
Var s = "akfjdlffdf \ 7fggfgfg \ 7 ghgh ";
Var arr = s. split ("\ 7 ");
Alert (arr. length );
Arr = null;
S = null;
Delete arr;
Delete s;
</Script>

\ 7 is a common string. It doesn't mean anything special.
Zhang zhanggang [authoritative expert]

[] Different js from {}

In JS, [] indicates an array, and {} indicates an object. It is generally used in JSON;
For example, var json = {"eles": ["aaa", "bbb", "ccc", "ddd"]};
The eles attribute value of the json object is an array of four elements;
You can obtain these values through json. eles [0], json. eles [1...
In addition, var arr = new Array (); In js, it can be equivalent to var arr = [];
I hope to help you and wish you good luck...

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.