Learn JS array on the official website of Liao Xuefeng

Source: Internet
Author: User

IndexOf () The position of a character
Slice    equivalent to a substring   slice of string
A = [' A ', ' B ', [+] (5) ["A", "B", 1, 2, 3]a.slice (0,3) (3) ["A", "B", 1]a.slice (3  ) (2) [2, 3]

Append pop () after push () is removed from the back

A.push (' h ')7A (7) ["A", "B", 1, 2, 3, 4, "H"]a.pop ()"H"A (6) ["A", "B", 1, 2, 3, 4]
Unshift () in front       of add shift () to delete the previous
A.unshift (7a) (7) [A, "a", "B", 1, 2, 3, 4]a.shift ()A (6) ["A", "B", 1, 2, 3, 4]

A.sort () sort

Reverse () Flip

splice(start, deleteCount, value, ...)  插入、删除或替换数组的元素      万能方法

                     obj.splice(n, 0 ,val) 指定位置插入元素                      obj.splice(n, 1 ,val) 指定位置替换元素                      obj.splice(n, 1 )     指定位置删除元素
A (6) [1, 2, 3, 4, "A", "B"]a.splice (2,0,8) []a (7) [1, 2, 8, 3, 4, "A", "B"]a.splice (2,1) [8]a (6) [1, 2, 3, 4, "A", "B"]a.splice (2,1,8) [3]a (6) [1, 2, 8, 4, "A", "B"]
Join () forms a string of array elements
a.join ()"1,2,8,4,a,b"

Learn JS array on the official website of Liao Xuefeng

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.