_javascript techniques for adding values and accessing values to an array in JavaScript

Source: Internet
Author: User

Through this article for you to introduce some of the small problems of the array, perhaps for everyone a little help, this article is not good, but also please forgive me heroes.

1.

var arr = [,,];
arr["BBB"]= "nor";
Arr[-]= "nor";
Console.log (arr); >> [,,, BBB: "Nor",-: "nor"]
//Console.log (ARR.BBB) >> "nor"

If we want to add a value to the array, added as [], if a negative number or string is written, it is added at the end of the array, and it is added as a key-value pair, so the next time you access the value, you can access it by using a dot, but if the numbers must be accessed through [].

2.

var arr = [,,];
arr["BBB"]= "nor";
Console.log (arr); [,,, BBB: "nor"]
Console.log (arr[]) undefined

If you add a value to the array by a string or negative number, you must also access the key value on the next visit

3.

var arr = [,,];
arr["BBB"]= "nor";
arr[-]=;
Arr.push ();
Console.log (arr); >> [,,,, BBB: "nor"]

It is worth noting that the value added through a string or negative number, that array will not add its length, and that this way to add will always be at the end of the array, because we use the push method to add 4 when we found that it did not add to the last, We all know that the push method adds a value to the end of the array. Maybe we can come to the conclusion that is numeric and numeric permutations, with key pairs aligned with key-value pairs.

This article through the above three points to a simple analysis of JavaScript in the array add value and Access values FAQ, I hope to help. At the same time, cloud Habitat Community Small series in this wish You happy Spring Festival!

Related Article

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.