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 does js create an one-dimensional array

2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

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

This article introduces the knowledge of "how to create an one-dimensional array in js". In the operation of practical 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. The array is directly measured "[]".

We can directly use "[]" to assign a value to a variable, which can be empty, so define an empty array:

Var a = []; / / empty array

Use the length property of the array to get the length of the array, with a return value of 0.

Console.log (a.length)

2. Define the array directly and initialize it, including multiple value lists directly in "[]", separated by commas.

Var a = [1,2,3]; / / an array containing specific elements

3. Use new Array () to construct an array

(1) if you call the Array () function directly without passing parameters, you can create an empty array.

Var a = new Array (); / / empty array

(2) if you pass multiple values (separated by commas) when you call the Array () function, you can create a real array.

Var a = new Array (1, 2, 3)

(3) if only one numeric parameter is passed when calling the Array () function, it means that only the length of the array, that is, the number of elements, is defined; the array element is empty, and the default value of each element is undefined. (an element whose value is not defined in the array and has no value between two commas in syntax is called an empty element.)

Var a = new Array (3); that's all for "how js creates an one-dimensional 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

Development

Wechat

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

12
Report