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

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;
主站蜘蛛池模板: 保亭| 东山县| 宁津县| 房山区| 交城县| 文成县| 微山县| 鄄城县| 文山县| 丘北县| 许昌县| 宁国市| 浦北县| 太仆寺旗| 阳江市| 德州市| 孝感市| 临潭县| 正安县| 沾化县| 宁陕县| 呼伦贝尔市| 晋宁县| 金华市| 庆阳市| 晋江市| 平南县| 长丰县| 通江县| 公安县| 班戈县| 高碑店市| 清水河县| 富阳市| 双桥区| 渝中区| 阿拉善盟| 孝义市| 辽阳县| 高雄县| 利津县|