Author: Not specified Language: javascript
Description: Not specified Timestamp: 2018-04-17 08:35:26 +0000
View raw paste Reply
  1. var sample = [1, 2, 3];
  2. // es5
  3. sample.forEach(function (elem, index){
  4.    console.log(elem + ' comes at ' + index);
  5. })
  6. // es6
  7. sample.forEach((elem, index) => `${elem} comes at ${index}`)
  8. /*
  9. output
  10. 1 comes at 0
  11. 2 comes at 1
  12. 3 comes at 2
  13. */var sample = [1, 2, 3];
  14. // es5
  15. sample.forEach(function (elem, index){
  16.    console.log(elem + ' comes at ' + index);
  17. })
  18. // es6
  19. sample.forEach((elem, index) => `${elem} comes at ${index}`)
  20. /*
  21. output
  22. 1 comes at 0
  23. 2 comes at 1
  24. 3 comes at 2
  25. */
View raw paste Reply