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 to use JavaScrip array

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

Share

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

This article introduces the knowledge of "how to use JavaScrip array". Many people will encounter such a dilemma in the operation of actual cases, 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!

JS's array is delimited with square brackets [], and the area wrapped in square brackets is the element of the array. Array elements are separated by commas

# Array creation

The array also has its constructor Array. The array is created by the constructor, and the parameter passed in is the initialization element of the array.

Var variable name = new Array (element 0, element 1.)

Var arr = new Array (); / / create an empty array var arr = new Array; / / create an array containing four digits var arr = new Array (4); / / create an array of 4 lengths full of null values

[] create directly

Var variable name = [element 0, element 1]

Var arr1 = []; / / create an empty array var arr2 = [1,2,3,4]; / / create an array of four values with multiple array items separated by commas var arr3 = [4]; / / create an array with only one element, and the element is the length and subscript of the 4 array

Length of the array: the same as the string, the array has a length attribute, the number of elements stored in the exponential group

Var str1 = 'abc';console.log (str1.length); var arr = [1, 3, 5, 5, 8]; console.log (arr.length)

Array subscript: because the array is ordered, it should have its own sequence number, and this sequence number is the corresponding subscript for each element, starting with 0 and ending with arr.length-1.

Var arr = ["zs", "ls", "ww"]; arr [0]; / / the value corresponding to subscript 0 is zs arr [2]; / / the value corresponding to subscript 2 is ww var arr = ['zs','ls','ww']; / / 0 12 / / subscript: 0 start arr.length-1 end length: 3 arr.length array value

Format: array name [subscript]

Gets the value corresponding to the array subscript, and returns undefined if the subscript does not exist.

Subscript range: 0 ~ arr.length-1

Var arr = ["red", "green", "blue"]; / / print: arr [0]; / / red print: arr [2]; / / blue print: arr [3]; / / the maximum subscript of this array is 2, so return the assignment of the undefined array

/ / format: array name [subscript] = value

/ / if the subscript has a corresponding value, the original value will be overwritten

# # adding elements to an array

That's all for "how to use JavaScrip Array". 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

Internet Technology

Wechat

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

12
Report