Introduction of the white road javascript array

Ban against the war - -
on the array, should be a very important knowledge javaScript, after all, there is an array of sources js thing (joke), then what is an array it?
Arrays can be said to be another form of expression, the array is characterized by the presence of data in the array is a sequence of objects, each corresponding to a data index (thanks to him), and is increased gradually from zero, array "length" of it, that is, the number of data stored in the array, the array should be said that you can put any type of data, including numbers, strings, boolean, null, undefined, function types, and so on, these can be a member of the array, but when we deal with the problem will find that we have the same type of data in an array, making it easier to deal with or solve the problem, after all, we learned the array, it is to go to solve practical problems thing.
1, to create an array of ways:
(1) declarative
var ARR = [A, B, C, D];
(2) a constructor argument
var arr = new Array ();
above two methods can be to create an array, one thing to note is that declarative way to create a digital release, then, is to open up a small space in the array, stored inside a number. Way constructor if you write a number in parentheses indicates is open in this array of two small space, and has no value, undefined;
2, to access an array of
array accesses, in fact, it can be quite simple, only need to index, such as: I want to access above a, then you can use an array name [subscript], note that index is zero-based.
3, through the array of
traversing it plainly, that is to say the data values in the array of each visit again, which requires data to which data out ok. Way to do that, to introduce the following two kinds of
(1) a for loop to traverse, such as:
for (var I = 0; I <arr.length; I ++) {
the console.log (ARR [I]);
}
obtained is each of the array data, then, would hold these values do other things slightly
(2) to traverse through for ... in, for example:
for (var I in ARR) {
the console.log (ARR [I]);
}
both ways are to go through the array, but also a difference therebetween what difference does it make, is not the same type of output worth it ,, little need to pay attention to the next, according to our need to choose.
4, array-valued
array-valued, then there is a need to master knowledge, what is array-valued it, with the assignment of variables there any similarities or differences yet. Here's a little detail about it.
In the js, this data type may be sub-divided into complex data types and simple data types,
complex data types including: an array / objects / functions, simple data types can be divided into: Type numeric / character string type / boolean / null / undefined can be called simple type, or a primitive type.
Time (1) when the basic data types assignment is to stack memory value exists, the assignment is the value of a copy, and then placed in a variable.
(2) Copy the data type, then that is their values are a heap space, stored in the stack memory, in fact, is an address, the equivalent is the house number, street number we can take this to the heap space to find the corresponding value. When the assignment is to address a copy, there is a variable, the variable can get this address to find the value of heap memory. When comparison is the same reason.
There are also an array of methods, these methods are able to grasp the full array of operations, today they would not be introduced, and then write the next chapter, the white js road. . .

Published an original article · won praise 4 · views 41

Guess you like

Origin blog.csdn.net/demo_new/article/details/104587892