Common problems with adding values to arrays and accessing values in JavaScript

  • 2020-12-16 05:50:39
  • OfStack

Through this article to introduce to you about the array of 1 small problems, may be a little help to you, this article is not good, also please forgive each hero.

1.


// var arr = [,,];
// arr["bbb"]="nor ";
// arr[-]="nor ";
// console.log(arr); >> [, , , bbb: "nor ", -: "nor "]
// console.log(arr.bbb) >> "nor "

If we want to add one value, an array to add, in the form of [] if writing is negative or added to the end of the string if it is in the array, and it is added in the form of key-value pairs, so next time you visit this value can use some form of access, but if it is number must be accessed by [].

2.


// var arr = [,,];
// arr["bbb"]="nor ";
// console.log(arr); [, , , bbb: "nor "]
// console.log(arr[]) undefined

If you add a value to an array by a string or negative number, the next time you access it, you must also access it as a key-value pair

3.


// var arr = [,,];
// arr["bbb"]="nor ";
// arr[-]=;
// arr.push();
// console.log(arr); >> [, , , , bbb: "nor "]
// console.log(arr.length); >> 

/ / it is worth noting that by adding the value string or a negative number, the array will not add its length, and will always use this way to add in the array of the back, because we are using push methods add number 4 when we found that it did not add is behind in the end, everyone know push method at the end of the add value to the array. Maybe there's one thing we can come up with and that's numbers and permutations, key-value pairs and key-value pairs.

I hope this article will help you by briefly analyzing the common problems of adding values to arrays and accessing values in JavaScript through the above three points. At the same time this site this site here I wish you a happy Spring Festival!


Related articles: