Many people always encounter js arrays when learning js, but many people don’t know what js arrays are? Let's explain js arrays and can js arrays be of different types? [Recommended reading: JS array operation and parsing methods summary]
1: What is a js array
Many people know that a variable can be stored as another value. If we want to store it as another value js, we can write like this:
var str = "js";
If we want the variable to be stored as three characters, we can directly store three values in the variable, as follows:
var str1= "CSS"; var str2= "jQuery"; var str3= "HTML";
The above method can only be suitable for relatively small arrays. If When it reaches dozens or hundreds of characters, it becomes very troublesome to write. For fairly large data, we need to consider using numerical values. Then in js, we can use a set of arrays to store characters, such as the three characters above. We can use the following code to express:
var arr = new Array("CSS","jQuery","HTML");
2: Can js arrays be of different types?
In js arrays, one thing to remember is that the arrays must store the same The string data type cannot be of different data types. If it is a string, it is the same as a string. If the data type is a numeric type, the two cannot be mixed together.
1. String data type:
var arr = new Array("CSS","jQuery","HTML");
2. Numeric data type:
var arr = new Array(2,4,8,16,32);
The above is what is a js array? A full explanation of whether js arrays can be of different types. If you want to know more about JavaScript tutorial, please pay attention to the php Chinese website.
The above is the detailed content of What is a js array? Can js arrays be of different types?. For more information, please follow other related articles on the PHP Chinese website!