4 small ways to manipulate arrays

Source: Internet
Author: User

First, push ()

Adds content to the last array. has a return value: array length

Second, Unshift ()

Adds content to the front of the array. return Value: Array length

Third, pop ()

Moves the last data of the divisor group. return Value: The data information that was removed.

Four, Shift ()

Removes the first bit of data from the divisor group. return Value: The data information that was removed.

Small example: 

var attr=[' 1 ', ' 2 ', ' 3 ', ' 4 ']//put the 4 in the array first, 1 to the last/*attr.pop ()///Remove the last 4 with a return value of 4;attr.unshift (Attr.pop ());/* Attr.shift () *///removes the first digit 1, whose return value is 1;attr.pop (Attr.shift ());

  

  

4 small ways to manipulate arrays

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.