One very common operation in programming is to iterate through an Array's contents, apply a function to each item, and create a new array containing the results. For example, let's say you wanted to loop through an array of stock objects and select only the name for display on screen. In this lesson we will demonstrate how to use the Array's map method to easily perform this operation with less code than a loop would require.

function getStockSymbols(stocks) {
return stocks.map(function(stock) {
return stock.symbol;
})
} 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));

[Javascript] The Array map method的更多相关文章

  1. JavaScript 对象Array,Map,Set使用

    for(int i = 0 :i < 3 ;i++ ){ //[重点说三遍] 在说明每个对象的用法之前,首先说明 JavaScript 对象的使用一定要注意浏览器的兼容性问题!尤其是IE的版本! ...

  2. [Javascript] The Array forEach method

    Most JavaScript developers are familiar with the for loop. One of the most common uses of the for lo ...

  3. [Javascript] The Array filter method

    One very common operation in programming is to iterate through an Array's contents, apply a test fun ...

  4. JavaScript中数组map()方法

    JavaScript 数组map()方法创建一个新的数组使用调用此数组中的每个元素上所提供的函数的结果.语法 ? 1 array.map(callback[, thisObject]); 下面是参数的 ...

  5. Javascript中Array.prototype.map()详解

    map 方法会给原数组中的每个元素都按顺序调用一次 callback 函数.callback 每次执行后的返回值组合起来形成一个新数组. callback 函数只会在有值的索引上被调用:那些从来没被赋 ...

  6. JavaScript Array.map

    Array.prototype.map() History Edit This article is in need of a technical review. Table of Contents ...

  7. [Javascript + rxjs] Using the map method with Observable

    Like an array, Observable has a map method that allows us to transform a sequence into a new Observa ...

  8. JavaScript Array map() 方法

    语法: array.map(function(currentValue,index,arr), thisValue) currentValue:必须.当前元素的值index:可选.当期元素的索引值ar ...

  9. javascript的Array.prototype.map()和jQuery的jQuery.map()

    两个方法都可以根据现有数组创建新数组,但在使用过程中发现有些不同之处 以下面这个数据为例: var numbers = [1, 3, 4, 6, 9]; 1. 对undefined和null的处理 a ...

随机推荐

  1. percona-xtrabackup安装及使用教程

    安装percona-xtrabackup依赖包(前提已安装mysql) yum -y install perl-CPAN perl-DBD-MySQL perl make gcc gcc-c++ pa ...

  2. AVPicture、AVFrame和AVPacket

    http://blog.csdn.net/ym012/article/details/6540065 从定义上可知,AVPicture是AVFrame的一个子集,他们都是数据流在编解过程中用来保存数据 ...

  3. 了解实时媒体的播放(RTP/RTCP 和 RTSP)

    http://blog.csdn.net/span76/article/details/12913307 RTP/RTCP RTP是基于 UDP协议的, UDP不用建立连接,效率更高:但允许丢包, 这 ...

  4. MyBatis学习总结1

    MyBatis是一个支持普通SQL查询,存储过程和高级映射的优秀持久层框架.MyBatis消除了几乎所有的JDBC代码和参数的手工设置以及对结果集的检索封装.MyBatis可以使用简单的XML或注解用 ...

  5. 宣布正式发布 Azure 媒体服务内容保护服务

    Mingfei Yan Azure媒体服务项目经理 我们非常高兴地宣布正式发布 Azure 媒体服务内容保护服务.这包括 Microsoft PlayReady许可服务和 AES明文密钥交付服务!此外 ...

  6. 从头开始编写一个Orchard网上商店模块(5) - 创建和渲染ProductCatalog的内容类型

    原文地址: http://skywalkersoftwaredevelopment.net/blog/writing-an-orchard-webshop-module-from-scratch-pa ...

  7. 安装Visual Studio2015后,使用VS2013开发的项目,在IIS访问都提示“公共语言运行时检测到无效的程序”的解决办法

    1.安装VS2015后,.NET Framework4.6会替换掉 C:\Windows\Microsoft.NET\Framework64\v4.0.30319 (如果使用的是windows7 64 ...

  8. c#打印机设置,取得打印机列表及相应打印机的所有纸张格式

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...

  9. ORA-00214: control file 控制文件版本不一致

    故障现象:今日学习oracle控制文件移动和修改,发现本机安装oracle数据库启动时只使用了一个控制文件.如下:SQL> select * from V$controlfile; STATUS ...

  10. LoadRunner 参数化详解

    可能稍微对LR 有些了解的人都知道LR 参数化的功能,今天请跟我来一起好好理一下. 首先,咱们先说一下为啥要用参数化?假如您录制了一个登录的脚本,如下所示, web_submit_form(" ...