1 String Object
String creation
(1) Create directly
var s= "Hello"; Console.log (s); Console.log (typeof s) >>hellostring
(2) Create with class
var s1=new String ("Hello"); Console.log (S1); Console.log (typeof S1) >>helloobject
Properties and functions for string objects
(1) X.length----get the length of the string
2 Array Object
Three ways to create an array
(1) var arrname = [element 0, Element 1,....]; var arr1=[11,222,333]; Console.log (arr1); Console.log (typeof arr1); (2) var arrname = new Array (element 0, Element 1,....), var arr2=new Array ("Yuan", 12,[10,7]); Console.log (ARR2); Console.log (typeof arr2), (3) var arrname = new Array (length), var cnweek=new array (7), Var arr3=new array (3); arr3[0]=12; Arr3[1]= "Yuan"; Arr3[2]=true; Console.log (ARR3); Console.log (typeof Arr3);
Properties and Methods
(1) Join method
X.join (BYSTR)----stitching array elements into strings
Console.log (Arr1.join ("--"));
(2) Concat method
X.concat (Value,...)
Console.log (ARR1.CONCAT);
(3) Array sort-reverse sort
X.reverse ()
X.sort ()
Console.log (Arr4.reverse ());
(4) Array slicing
X.slice (start, end)
var arr2=[12,32,33,100]; Arr2.unshift (a); Console.log (ARR2); Arr2.shift (ARR2); Console.log (ARR2);
Using annotations
x represents the Array object
Start indicates the starting position index
End is the ending position the next array element index number
The first array element index is 0
Start, end can be negative,-1 represents the last array element
End ellipsis is equivalent to intercepting all array elements from the start position
Console.log (Arr4.slice (0,2));
(5) Deleting a sub-array
X. Splice (Start, DeleteCount, value, ...)
Using annotations
x represents the Array object
The main purpose of splice is to delete and insert the specified position in the array
Start indicates the starting position index
DeleteCount to delete the number of array elements
Value represents an array element that is inserted at the drop location
The value parameter can be omitted
Console.log (Arr4.splice (1,0,222)); Console.log (ARR4);
(6) Push and pop for arrays
Push Pop These two methods simulate a stack operation
X.push (value, ...) Press Stack
X.pop () Bomb stack
Using annotations
x represents the Array object
Value can be any value such as a string, a number, an array, etc.
Push is to add value values to the end of the array x
Pop is the last element of the array x is deleted
var arr1=[12,32,5,33,100]; Arr1.push (in); Console.log (arr1); Arr1.pop (arr1); Console.log (ARR1);
(7) The shift and unshift of the array
X.unshift (Value,...)
X.shift ()
x represents the Array object
Value can be any value such as a string, a number, an array, etc.
Unshift is the start of inserting value values into the array x
Shift is to delete the first element of the array x
Summary://Convert to String Console.log (Arr1.tostring ()); Console.log (typeof arr1.tostring ());//js regardless of the key plus no quotes, no, the default string // values, whether single or double quotes, can be d={"name": "Cobila", "Age": "Max"}; Console.log (d); Console.log (typeof D); D1={name: "Cobila", Age: "*"}; Console.log (d1); Console.log (typeof D1); Traversing the key-value pair data type for (var key in D1) { console.log (key); } In JS, when the array is traversed, the index value is obtained;
JS Object 1