javascript knowledge

1. For looping on arrays, for and xxx.map(function(v){do something;}) and xx.forEach(function(v){do something;})

2. es6 writes the function in a simple way (pars)=>{do something;} If pars has only one parameter, the parentheses can be omitted; if the curly braces are return directly, the curly braces can be omitted;

eg :

var xxx = [1,2,3,4]

var sum = 0

 

xxx.forEach(v=>sum+=v) means to loop through the xxx array, sum each element v in xxx, and put it in the sum

3. If you are not sure how many parameters of the function, you can use ... to modify, there are es6 tutorials on the MOOC online, see https://www.imooc.com/video/16699

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325311760&siteId=291194637