Array is one part of programming language, which i really don’t like. But I met it everyday, so here is some basic methods for how to deal with array.
1. x.push()x.push() is adding element to the end of array
2. x.unshift()x.unshift() is adding element to the beginning of array
x.pop() is to delete the last element from array
x.shift() is to delete the first element from array
x.indexOf() can show which position the element is, in this example, pear is x, so the number is 1 . If there is no this element in array, number will be -1.
1.easy way to add element at the end of array
But we cannot use this way to add element to any position.
And adding element with high indexes can create undefined “holes” in an array
we also can use delete to remove element from array. However, it leaves undefined “hole “, so try to use pop() and shift() instead.
How to add new elements in any position. And how to remove any element from any position.