Home > Web Front-end > JS Tutorial > body text

Arrary method of JS

php中世界最好的语言
Release: 2018-03-16 15:45:29
Original
2653 people have browsed it

This time I will bring you Arrary method of JS, use Arrary method of JSAttention What are the matters? Below are practical cases. Let’s take a look.

Stack method:

js provides two methods to implement stack-like operations: push(), pop()

The stack is A LIFO (last in first out) data structure,

var arr = [1,2,3,4];
arr.push(5);  // result: [1,2,3,4,5]arr.pop();  // result: [1,2,3,4]
Copy after login

queuemethod:

The queue data structure access rule is FIFO (first in first out). The queue adds items at the end of the list and removes items at the front of the list. The method to achieve this operation is: shift()

var arr = [1,2,3,4];
arr.push(5);  // result: [1,2,3,4,5]arr.shift();  // result: [2,3,4]
Copy after login

Reordering:

reverse() method implements reordering

var arr = [1,2,3,4,5];
arr.reverse();  // [5, 4, 3, 2, 1]
// 另外一种重排序的方法Array.sort()
Copy after login

Splicing:

var arr = [1,2,3];var arr2 = [4,5,6];
arr.concat(arr2);  // result: [1, 2, 3, 4, 5, 6]
Copy after login

I believe you have mastered the method after reading the case in this article. For more exciting information, please pay attention to the php Chinese website Other related articles!

Recommended reading:

Detailed explanation of JavaScript timer

Events and callback functions of JavaScript running mechanism

Detailed explanation of the browser’s multi-threading mechanism

The above is the detailed content of Arrary method of JS. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template