In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-19 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article will explain in detail how to create an array in javascript. The editor thinks it is very practical, so I share it with you as a reference. I hope you can get something after reading this article.
Javascript to create an array method: 1, use the array to directly measure "[]", syntax "var a = [value list];", the value list is empty, can also be separated by "," multiple values; 2, use "new Array ()" to construct an array, syntax "var a=new Array (value list);".
The operating environment of this tutorial: windows7 system, javascript1.8.5 version, Dell G3 computer.
There are two ways for javascript to create an array
"array direct quantity"
"Array () function"
1. Array direct quantity "[]"
1) We can directly use "[]" to assign a value to a variable. "[]" 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)
At this point, we can assign a value to an empty array in the form of array name [subscript] = value.
A [0] = 1 tera [1] = "hello"
The array subscript can be not only a number, but also a text string, so the array is an associative array.
A ["name"] = "Zhang San"; a ["age"] = 23
If the array's subscript value is out of range, such as a negative, floating-point, Boolean, object, or other value, JavaScript automatically converts it to a string and defines it as an associative array.
2) you can also directly define the array and initialize the
Include multiple value lists directly in "[]", separated by commas.
Var a = [1,2,3]; / / an array containing specific elements
Use the length attribute of the array to get the length of the array, and the return value is the number of elements of the array that are defined.
2. Use new Array () to construct an array
1) if you call the Array () function directly, without passing arguments, you can create an empty array.
Var a = new Array (); / / empty array
Use the length property of the array to get the length of the array, with a return value of 0.
V
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 the Array () function is called, 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)
An array like this that contains one or more vacant elements is also called an empty array.
This is the end of the article on "how to create an array of javascript". I hope the above content can be of some help to you, so that you can learn more knowledge. if you think the article is good, please share it for more people to see.
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.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.