官术网_书友最值得收藏!

Arrow functions

You need to iterate over the elements of an array; normally, you would write something like this:

var data = ['Ronaldo', 'Messi', 'Maradona'];
data.forEach(function (elem) {
console.log(elem)
});

With the arrow functions, you can refactor your code and write something as follows:

var data = ['Ronaldo', 'Messi', 'Maradona'];
data.forEach(elem => {
console.log(elem);
});

The arrow (=>) operator defines a function in one line, making our code readable and ordered. First, you need to declare the inputs; the arrow will send these params to the function body defined by the operator:

// We could transform this
let sum = function(num) {
return num + num;
};
// Into just this
let sum = (num) => num + num;
主站蜘蛛池模板: 磐石市| 长泰县| 驻马店市| 通山县| 文水县| 响水县| 永定县| 抚宁县| 乌兰浩特市| 巴塘县| 龙游县| 海丰县| 泊头市| 兰州市| 丘北县| 浦城县| 定日县| 焉耆| 屏南县| 富锦市| 宝清县| 通渭县| 杨浦区| 天镇县| 峨边| 左云县| 若尔盖县| 尤溪县| 平安县| 东乌珠穆沁旗| 公主岭市| 襄樊市| 抚州市| 平塘县| 大新县| 宁津县| 丰城市| 夏邑县| 玉屏| 凯里市| 聂荣县|