[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 ...
随机推荐
- RxJava开发精要3-向响应式世界问好
原文出自<RxJava Essentials> 原文作者 : Ivan Morgillo 译文出自 : 开发技术前线 www.devtf.cn 转载声明: 本译文已授权开发者头条享有独家转 ...
- Cocos2d-x CCEditBox & CCTextFieldTTF
下面简单记录一下如何Cocos2d-x中创建输入编辑框.在引擎中为我们提供了这样两个类:CCEditBox 和 CCTextFieldTTF. 一.CCEditBox ①这个类文件的位置 ②这个类 ...
- WCF - WAS Hosting
WCF - WAS Hosting To understand the concept of WAS hosting, we need to comprehend how a system is co ...
- Java之String,StringBuffer,StringBuilder类
在 java 语言中, 用来处理字符串的的类常用的有 3 个: String.StringBuffer.StringBuilder. 它们的异同点: 1) 都是 final 类, 都不允许被继承; 2 ...
- 解决因block的损坏而导致hdfs启动后进入安全模式
问题描述: 以单机伪分布式方式安装了hadoop2.7.1,并在该机器上安装了hive1.2.1.首先执行 sbin/start-dfs.sh 启动hdfs服务,然后执行hive,这时hive脚本启动 ...
- BZOJ_1833_[ZJOI2010]_数字计数_(数位dp)
描述 http://www.lydsy.com/JudgeOnline/problem.php?id=1833 统计\(a~b\)中数字\(0,1,2,...,9\)分别出现了多少次. 分析 数位dp ...
- 转自 Good morning 的几句精辟的话
1.志愿者招募 根据流量平衡方程来构图非常方便,而且简单易懂,以后可能成为做网络流的神法之一 简单记一下流量平衡方程构图法的步骤: a.列出需求不等式 b.通过设置松弛变量,将不等式变成等式 c.两两 ...
- Deep Learning Overview
[Ref: http://en.wikipedia.org/wiki/Deep_learning] Definition: a branch of machine learning based on ...
- AlarmManager用法
源http://blog.csdn.net/wangxingwu_314/article/details/8060312
- LinkedList源码解析
LinkedList是基于链表结构的一种List,在分析LinkedList源码前有必要对链表结构进行说明.1.链表的概念链表是由一系列非连续的节点组成的存储结构,简单分下类的话,链表又分为单向链表和 ...