First, the data type
string example.
var str = ' Hello world '; str[5] = '. ' ; var len = str.length; var upperstr = str.touppercase (); var lowerstr = str.tolowercase (); var i = Str.indexof (' World '); var substr = str.substring (6, 11);
View Code
An array example.
vararr = [0, 1.0, ' 1 ',true, Undefined,NULL, []];varLen =arr.length;varelement = Arr.indexof (0);varSubarr = Arr.slice (0, 5);//add an element to the end or delete an elementArr.push (1, 2, 3); Arr.pop ();//add an element to the head or delete an elementArr.unshift (4, 5, 6); Arr.shift ();varDelarr = Arr.splice (0, 3, ' 7 ', ' 8 ', ' 9 ');//Insert after deleting contentArr.concat (Delarr);//Connection Arrayvarstr = arr.join ('-');//connect using the specified stringArr.sort (); Arr.reverse ();View Code
An example object.
var Player = { , ' Stephen Curry ', ' Golden State Warriors ',}; player[// access Properties // Add properties Delete// Delete Properties inch // determines whether a property has // determines whether a property has its own
View Code
Second, Process Control
var arr = []; for (var i = 0; i < i++) Arr.push (i); var sum = 0; for (var in arr) if (j% 2 = = = 0) + = parseint (j); alert (sum);
View Code
For...in loops due to historical legacy issues, which traverse the actual object's property name. When we manually add some extra attributes to the object, the for...in loop will also traverse the attributes we added as collection elements. The For...of loop solves these problems by traversing only the collection elements themselves.
var arr = [0, 1, 2, 3, 4= "MyArray"; var str = '; for (var I of arr) + = I;alert (str);
View Code
Three, set and mapping
The default object representation of JS is visible as a insinuate data structure in other languages, but the problem is that the health value must be a string. The ES6 specification introduces a new collection and mapping data type.
var New map (); Map.set (1, "Spring"); Map.set (2, "Summer"); map. Delete (1); var New set (); Set.add ("Autumn"); Set.add ("Winter"); set. Delete ("Autumn");
View Code
JavaScript notes: Basic knowledge