ES5 learning tutorial Array object, es5array object

Source: Internet
Author: User

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.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.