JavaScript string
A string is a collection of characters, including English letters, punctuation marks, special symbols, Chinese characters, and so on.
In JavaScript, strings can be represented by double quotes ("") or single quotes (' ").
Double quotes and single quotes must appear in pairs, which can contain single quotes, and can contain double quotes inside the single quotation mark.
For example:
Copy Code code as follows:
var mystr1= "My name is ' Xiaohua '!" ";
var mystr2= ' "Is my dream!", Tom said. ' ;
The length of the string is obtained by the lengths, for example:
Copy Code code as follows:
Mystr1.length;
Mystr2.length;
JavaScript array
Arrays are used to store a series of values in a separate variable.
In JavaScript, you can define an array in several ways.
Use keyword new to create an array object
For example, create an array named MyArray and assign the value:
Copy Code code as follows:
var myarray=new Array ();
Myarray[0] = "zhangming";
MYARRAY[1] = "Zhaowei";
MYARRAY[2] = "Wanghua";
You can also assign values while creating an object:
Copy Code code as follows:
var myarray=new Array ("zhangming", "Zhaowei", "Wanghua");
Create an array directly using []
For example, create an array named MyArray and assign the value:
Copy Code code as follows:
var myarray=[];
Myarray[0] = "zhangming";
MYARRAY[1] = "Zhaowei";
MYARRAY[2] = "Wanghua";
Of course, you can also assign values at the same time you create an array:
Copy Code code as follows:
var myarray=["zhangming", "Zhaowei", "Wanghua"];
Create a group of key/value pairs
For example, create an array named MyArray and assign the value:
Copy Code code as follows:
var myarray=new Array (); You can also use Var myarray=[];
myarray["zhangming"] = "22";
myarray["Zhaowei"] = "21";
myarray["Wanghua"] = "30";
Modifying an array
Arrays can be modified after they are created and assigned, for example:
Copy Code code as follows:
Myarray[0] = "zhangming_1";
MYARRAY[1] = "zhaowei_1";
myarray["zhangming"] = "42";
myarray["Zhaowei"] = "61";
Array length
In JavaScript, you get the length of an array by length, for example:
Copy Code code as follows:
The above mentioned is the entire content of this article, I hope you can enjoy.