He can also insert an array. Specific methods:
var array1 = new Array ("1", "2", "3", "4");
Array1.splice (1, 0, "5");//After the 2nd element, insert 5; If the 2nd parameter is 0, it is not deleted.
document.write (array1+ "<br>"); Output 1, 5, 2, 3,4
Array1.splice (2,3, "7", "8")//delete the 3rd element after the 3 elements. Which is the 3rd, 4th, and 5th elements. And then insert the 7,8 in this position.
document.write (array1)//Output 1, 5, 7,8
Note: Unlike concat (), splice does not expand the parameters that he inserts. That is, if you insert an array, he is inserting the array itself, not the element of the array.
When Concat () inserts an array, it expands to insert the elements in the array, but when the inserted array
When there is an array, it will not unfold.
7): Push () method and Pop () method:
Push (): Appends one or more arrays to the tail of the array.
Pop (): Deletes the last element of the array.
var array1 = new Array ("1", "2", "3", "4");
Array1.push ("5");
document.write (array1+ "<br>"); Output 1, 2, 3, 4,5
Array1.pop ()
document.write (array1)//Output 1, 2, 3, 4
8): Unshift () method and Shift () method:
To the push and pop ...
Unshift (): Attaches one or more arrays to the head of the array.
Shift (): Deletes the first element of an array.
Some of the methods of arrays are more, and they look more annoying. So everyone should be a little patient.
In addition, you can refer to this article;
Summary: This chapter mainly discusses some methods of object and array. More difficult to remember and difficult to understand. But everything is a difficult and easy process. Once did not understand, see again ... Read a book for a time, its meaning from the present ...
Maybe you don't need to read it 100 times. ^_^.
is not feeling to see so many JS concept, already can't wait to write some examples of what. All right.
The next chapter we have a little combat ....
If you still don't understand, Google can search for information. (
Or contact me, you can go to my blog to give me a message: