Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How js parses php Array objects

2025-02-24 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/01 Report--

This article introduces the knowledge of "how js parses php array objects". In the operation of actual cases, many people will encounter such a dilemma, so let the editor lead you to learn how to deal with these situations. I hope you can read it carefully and be able to achieve something!

1. Introduction

1.1 description

An array is an ordered collection of values. Each value is called an element, and each element has a position in the array, represented by a number, called an index. JavaScript arrays are untyped: array elements can be of any type, and different elements in the same array may have different types. JavaScript authoritative Guide (sixth Edition)

1.2 definition method

Var names=new Array ("Zhang San", "Li Si", "Wang Wu")

/ / or

Var names= [Zhang San, Li Si, Wang Wu]

1.3 Properties

Length: represents the length of elements in an array.

two。 Example method commonly used methods:

1) unshift (): insert an element in the head of the array

2) shift (): removes and returns the first element of the array

3) push (): insert elements at the end of the array

4) pop (): removes and returns the last element of the array

2.1 concat (): join elements into an array. The original array will not be modified and a new array will be returned.

Parameters:

① value1,value2.valueN: any number of valu

Return value:

{Array} A new array containing the original Array and newly added elements.

Example:

Var demoArray= ['await,' baked,'c']

Var demoArray2=demoArray.concat ('e')

Console.log (demoArray); / / = > demoArray: the original array does not change.

Console.log (demoArray2); / / = > ['axiomagy, pageantry, pageantry, cinnamon,']

2.2 every (): iterate through the elements in turn to determine whether each element is true

Parameters:

① function (value,index,self) {}: each element uses this function to determine whether it is true or not, and when one is judged to be false, the traversal ends immediately.

Value: elements that the array traverses

Index: element serial number

Self: Array itself

Return value:

{Boolean}: true; is returned only if each element is true. As long as one is false, false is returned.

Example:

Var demoArray= [1, 2, 3]

Var rs=demoArray.every (function (value, index, self) {

Return value > 0

})

Console.log (rs); / / = > true

2.3 filter (): iterates through the elements in turn, returning a new array containing eligible elements

Parameters:

① function (value,index,self) {}: each element calls this function in turn, returning a new array containing eligible elements.

Value: elements that the array traverses

Index: element serial number

Self: Array itself

Return value:

{Array} A new array containing eligible elements

Example:

Var demoArray= [1, 2, 3]

Var rs=demoArray.filter (function (value, index, self) {

Return value > 0

})

Console.log (rs); / / = > [1,2,3]

2.4 forEach (): iterates through the elements in turn, executing the specified function; no return value

Parameters:

① function (value,index,self) {}: this function is called by each element in turn

Value: elements that the array traverses

Index: element serial number

Self: Array itself

Return value: none

Example:

Var demoArray= [1, 2, 3]

DemoArray.forEach (function (value, index, self) {

Console.log (value); / / = > output: 1 2 3

})

IndexOf (): looks for matching elements in the array. If there is no matching element,-1 is returned. Use the "= =" operator when looking up, so distinguish between 1 and'1'

Parameters:

① value: the value to look for in the array.

② start: the location of the sequence number to start the search, or 0. 0 if omitted.

Return value:

{Int}: returns the sequence number of the first matching value in the array, or-1 if it does not exist

Example:

['await,' baked,'c'] .indexOf ('a'); / / = > 0

['averse,' baked,'c'] .indexOf ('averse, 1); / / = >-1

['await,' baked,'c'] .indexOf ('d'); / / = >-1

[1, 2, 3] .indexOf ('1'); / / = >-1: the'= = 'matching method adopted

2.6 join (): splices all elements in the array into a string with a delimiter

Parameters:

① sparator {String}: the delimiter between elements, if omitted, is separated by default because of the English comma','.

Return value:

{String}: a string of elements spliced with sparator as a delimiter.

Example:

['averse,' baked,'c'] .join (); / / = > 'arecalogical brecedence c'

['await,' baked,'c'] .join ('-'); / / = > 'amurbmurc'

2.7lastIndexOf: reverse look for matching elements in the array. If there is no matching element,-1 is returned. Use the "= =" operator when looking up, so distinguish between 1 and'1'

Parameters:

① value: the value to look for in the array.

② start: the location of the sequence number to start the search. If omitted, the search starts with the last element.

Return value:

{Int}: start from right to left to find the sequence number of the first matching value in the array. If it does not exist, return-1

Example:

['averse,' baked,'c'] .lastIndexOf ('a'); / / = > 0

['averse,' baked,'c'] .lastIndexOf ('averse, 1); / / = > 0

['averse,' baked,'c'] .lastIndexOf ('d'); / / = >-1

[1, 2, 3] .lastIndexOf ('1'); / / = >-1: the'= = 'matching method adopted

That's all for "how js parses php array objects". Thank you for reading. If you want to know more about the industry, you can follow the website, the editor will output more high-quality practical articles for you!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report