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 JavaScript uses separate variable names to store multiple values

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

Share

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

This article mainly introduces how JavaScript uses separate variable names to store multiple values, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

JavaScript Array object

The Array (array) object is used to store a series of values using separate variable names.

Define array

Array objects are used to store a series of values in separate variable names.

Use the keyword new to create array objects. The following code defines an array object named myArray:

Var myArray=new Array ()

By assigning values to an array, you can add as many values as you want, just as you can define as many variables as you need.

There are two ways to assign values to an array:

1 、

Var mycars=new Array () mycars [0] = "Saab" mycars [1] = "Volvo" mycars [2] = "BMW"

You can also use an integer argument to control the capacity of the array:

Var mycars=new Array (3) mycars [0] = "Saab" mycars [1] = "Volvo" mycars [2] = "BMW"

2 、

Var mycars=new Array ("Saab", "Volvo", "BMW")

When specifying numeric or logical values in an array, the variable type should be a numeric variable or a Boolean variable, not a character variable.

Access array

You can access a particular element by specifying the array name and index number. For example:

[xss_clean] (mycars [0])

Note: the above line of code will output Saab.

Modify values in an existing array

To modify a value in an existing array, simply add a new value to the specified subscript:

Mycars [0] = "Opel"; [xss_clean] (mycars [0])

Note: at this point, the above line of code will output Opel.

Create an array

Create an array, assign values to it, and then output these values:

Var mycars = new Array () mycars [0] = "Saab" mycars [1] = "Volvo" mycars [2] = "BMW" for

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