[Javascript] The Array map method
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的更多相关文章
- JavaScript 对象Array,Map,Set使用
for(int i = 0 :i < 3 ;i++ ){ //[重点说三遍] 在说明每个对象的用法之前,首先说明 JavaScript 对象的使用一定要注意浏览器的兼容性问题!尤其是IE的版本! ...
- [Javascript] The Array forEach method
Most JavaScript developers are familiar with the for loop. One of the most common uses of the for lo ...
- [Javascript] The Array filter method
One very common operation in programming is to iterate through an Array's contents, apply a test fun ...
- JavaScript中数组map()方法
JavaScript 数组map()方法创建一个新的数组使用调用此数组中的每个元素上所提供的函数的结果.语法 ? 1 array.map(callback[, thisObject]); 下面是参数的 ...
- Javascript中Array.prototype.map()详解
map 方法会给原数组中的每个元素都按顺序调用一次 callback 函数.callback 每次执行后的返回值组合起来形成一个新数组. callback 函数只会在有值的索引上被调用:那些从来没被赋 ...
- JavaScript Array.map
Array.prototype.map() History Edit This article is in need of a technical review. Table of Contents ...
- [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 ...
- JavaScript Array map() 方法
语法: array.map(function(currentValue,index,arr), thisValue) currentValue:必须.当前元素的值index:可选.当期元素的索引值ar ...
- javascript的Array.prototype.map()和jQuery的jQuery.map()
两个方法都可以根据现有数组创建新数组,但在使用过程中发现有些不同之处 以下面这个数据为例: var numbers = [1, 3, 4, 6, 9]; 1. 对undefined和null的处理 a ...
随机推荐
- 未来 USB Type-C 将可靠软体判断线材是否符合规定
USB Type-C 插头允许通过的电流和功率比过去常见的 USB 规范要大得多,因此从市面上「随便买一条」USB Type-C 的充电线的危险也同样大得多,毕竟不是所有的线材能承受的电流都一样,万一 ...
- Java-Swing嵌入浏览器(二)
这是qtjambi利用webview来做嵌入式浏览器,下面是我的工程目录. 运行效果如下图: 代码相关: package qtBowers; import com.trolltech.qt.core. ...
- 【HDOJ】1203 I NEED A OFFER!
DP问题. #include <stdio.h> #define MAXNUM 10002 int main() { int m, n; int cost[MAXNUM]; // the ...
- Linux复制指定目录下的文件夹结构
[root@ebs12vis ~]# su - applmgr[applmgr@ebs12vis ~]$ cd $APPL_TOP/inv[applmgr@ebs12vis inv]$ find . ...
- Sublime Text修改显示图标
选择喜欢的图片 首先你需要选择一个中意的图片做为新的图标,格式可以是png,jpg,gif的 转为ico格式 我们需要ico格式的图片,所以需要将上述的图片转换一下格式.同样,转ico格式的软件很多, ...
- PHP 'ext/gd/gd.c' gdImageCrop空指针返回拒绝服务漏洞
漏洞版本: PHP 5.5.x 漏洞描述: CVE ID:CVE-2013-7327 PHP是一种HTML内嵌式的语言. PHP 'ext/gd/gd.c' gdImageCrop函数没有检查返回值, ...
- sql点滴39—解决数据库日志文件过大的问题
随着数据库使用时间增长,日志文件也在不停的增大,这里介绍几种方法减小这个文件的方法. 1.直接删除log文件(一般不建议) 分离数据库.分离数据库之前一定要做好数据库的全备份,选择数据库——右键——任 ...
- Oracle 12c创建用户时出现“ORA-65096: invalid common user or role name”的错误
这篇文章主要介绍CDB和PDB的基本管理,资料来源oracle官方. 基本概念: Multitenant Environment:多租户环境 CDB(Container Database):数据库容器 ...
- 转(NLP必读)
如果你刚接触自然语言处理并对她感兴趣,最好读几本这方面的书籍,除了能让你知道自然语言处理各个领域是干什么的外,还能培养一下NLP的感觉.以下四本书是我读研期间阅读和接触过的,如果您还有好书推荐,欢迎补 ...
- 解决 MyEclipse 10 中 JSp页面 “return false” 报错问题
1.MyEclipse ->. Preferences 2.validation ->>找到JavaScript validator for Js files builder 下面 ...