ES5 learning tutorial Array object, es5array object
Preface
Many new things added in ES5 will help us write Javascript. The following describes the Array objects in ES5. Let's take a look at them.
1. syntax for creating an Array object:
new Array();new Array(size);new Array(element0, element1, ..., elementn)
Ii. Attributes
| Attribute |
Description |
| Constructor |
Returns a reference to the array function that creates this object. |
| Length |
Sets or returns the number of elements in the array. |
| Prototype |
Allow adding attributes and methods to objects |
Iii. Common Methods
| Method |
Description |
| Concat () |
Concatenate two or more arrays and return results |
| Join () |
Put all elements of the array into a string. Elements are separated by specified delimiters. |
| Pop () |
Delete and return the last element of the array |
| Push () |
Add one or more elements to the end of the array and return a new length. |
| Reverse () |
Reversing the order of elements in an array |
| Shift () |
Delete and return the first element of the array |
| Unshift () |
Add one or more elements to the beginning of the array and return a new length. |
| Slice () |
Returns the selected element from an existing array. |
| Sort () |
Sorts elements of an array. |
| Splice () |
Delete elements and add new elements to the array |
| ValueOf () |
Returns the original value of a string object. |
Iv. Example
//concat()let a = [1,2,3]a.concat(4,5) //[1,2,3,4,5]//join()let a = [1,2,3]a.join() //1,2,3//slice()let a = [1,2,3]a.slice(1) //[2,3]let a = [1,2,3]a.slice(1,2) //[2]//splice()let a = [1,2,3,4,5]a.splice(1,1) //[2]let a = [1,2,3,4,5]a.splice(1,1,'hzzly') //[2]a //[1, "hzzly", 3, 4, 5]
Summary
The above is all the content of this article. I hope the content of this article will help you in your study or work. If you have any questions, please leave a message, thank you for your support.