Tips on some JavaScript, reproduced from HTTPS://WWW.GEEKJC.COM/POST/5A0A8C9A592E38541F7703C8.
The 1IF statement can be abbreviated with a three-mesh operation:
const x = 20;
if (x > 10) {
} else {
Answer = ' less than 10 ';
}
Const ANSWER = x > 10? ' Greater than ': ' less than 10 ';
2. String concatenation:
var arr = [{ "name": "Dachun", "age": +, " sex": "Male" }];for (Let i = 0;i<arr.length;i++) { Console.log ("Name:" + Arr[i].name + "Age:" + Arr[i].age + "Gender:" + Arr[i].sex);} ES6 string concatenation: for (Let i = 0;i<arr.length;i++) {console.log (' Name: ${arr[i].name} Age: ${arr[i].age} Gender: ${arr[i].sex} '); }//Note: In the ' Write variable, the ESC key below the English state can be pressed out '
3. Arrow functions
function SayHello (name) { console.log (' Hello ', name);} SetTimeout (function () { console.log (' Loaded ')}, () List.foreach (function (item) { Console.log (item);}); /with arrow function shorthand: SayHello = name + console.log (' Hello ', name); SetTimeout (() = Console.log (' Loaded '); List.foreach (item = Console.log (item));
4, the array to go to the weight (the key qaq the question several times have this)
var arr = [1, 1, 2, 2, 3, 3]; function Unique (arr) {let res = []; for (var i = 0;i<arr.length;i++) {for (var j = 0; j<res.length;j++) { if (arr[i] = = = Res[j]) {break; }} if (j = = = Res.length) { res.push (arr[i]);} } return res; }console.log (arr); Es6 Set method function unique (arr) {return array.from (new Set (arr)); } Console.log ("Es6set method:", Unique (arr));
JavaScript shorthand techniques reproduced continuous handling, aspects of their own view