Most JavaScript developers are familiar with the for loop. One of the most common uses of the for loop is to iterate through the items in an array. In this lesson, we will learn how to replace the for loop with the Array's forEach method - and shorten your code in the process.

function getStockSymbols(stocks) {
var symbols = []; stocks.forEach(function(stock) {
symbols.push(stock.symbol);
}); return symbols;
} var symbols = getStockSymbols([
{ symbol: "XFX", price: 240.22, volume: 23432 },
{ symbol: "TNZ", price: 332.19, volume: 234 },
{ symbol: "JXJ", price: 120.22, volume: 5323 },
]); console.log(JSON.stringify(symbols));

最新文章

  1. EasyUI中那些不容易被发现的坑——EasyUI重复请求2次的问题
  2. VOC2007检测任务的评估标准
  3. 关于activity的启动模式
  4. SPM paired t-test步骤
  5. Python 写Windows Service服务程序
  6. fopen的第一个参数不能有'\n'
  7. iar 错误解决
  8. SQL Server同步复制问题排查方法
  9. Marvelous Mazes
  10. linux定时
  11. Linux资源控制-CPU和内存【转】
  12. Java 包(package)详解
  13. Ubuntu Server 14.04在VMware安装的一些事儿
  14. 在windows64位Anaconda3环境下安装XGBoost
  15. BIGIP-LTM中的NAT和SNAT
  16. UEditor工具栏上自定义按钮、图标、事件和右击菜单添加自定义按钮
  17. java中的循环方法(附带本人遇到的坑)
  18. Postman 安装及使用入门教程 (谷歌浏览器插件版)
  19. GetSystemInfo()
  20. 再谈java clone 以及 浅/深拷贝

热门文章

  1. perl的输出缓冲
  2. 在redhat6.4下安装 Oracle® Database 11g Release 2
  3. Visual Studio原生开发的10个调试技巧(转)
  4. netsh命令
  5. 一步步写STM32 OS【四】OS基本框架
  6. ifconfig命令
  7. linux下安装
  8. Windows下部署Git Server端
  9. OpenStack swift安装
  10. vijosP1413 Valentine’s Present