1. The pop()
function is used to move the last element in the group; the shift()
function moves the first item in the array, and unshift
(moves in) an element to the head of the arrays.
For example:
varMyArray = [["John", at], ["Dog",3]];varA=myarray.pop ();//var myArray = [["John", 23]]; Move out the lastvarA=myarray.shift ();//var myArray = [["Dog", 3]]; move out of the firstvarC=myarray.unshift (["CCC",1]);//var myArray =[["CCC", 1],["John", [["Dog", 3]]; Array ["CCC", 1] inserted the head, became the first
2, all the comparison operators return a Boolean value, or it is either true
false
. Use if/else
statements to do comparisons and then return true
or false
have become a consensus among everyone:
For example:
function IsEqual (b) { if (a = = b) {returntrue; Else { returnfalse;} }
can be simplified into:
function IsEqual (b) { return a = = = b;}
3, there are two ways to access the object properties, one is the dot operator ( .
), one is the bracket operator ( []
). When you know the name of the property, use the dot operator.
1) dot operator ( .
)
For example:
varMYOBJ ={ Prop1:"Val1", prop2:"Val2"};varProp1val = MYOBJ.PROP1;//Val1varProp2val = MYOBJ.PROP2;//Val2//orvarTestobj = { "Hat": "Ballcap", "shirt": "Jersey","Shoes":"Cleats"};varHatvalue = Testobj.hat;//BallcapvarShirtvalue = Testobj.shirt;//jersey
2) Bracket operator ( []
): If the name of the property you want to access has a space, you can only use the bracket operator ( []
).
varMYOBJ = { "Space Name":"Kirk", "More Space":"Spock"};myobj["Space Name"];//Kirkmyobj['More Space'];//Spock
Tip: If there are spaces in the attribute name, you must enclose the attribute name in single or double quotation marks.
Little notes about JavaScript syntax