As an example, if Jason was riding the roller coaster (and when isn’t he), your goal would be to change his cell from ["Jason", "Millhouse"] to just "Jason Millhouse". Notice that an array goes in to the function you will build, but a string comes out.

var passengers = [ ["Thomas", "Meeks"],
["Gregg", "Pollack"],
["Christine", "Wong"],
["Dan", "McGaw"] ];
var modifiedNames = passengers.map(function(cell){
return cell[0] +" "+cell[1];
});
var modifiedNames = [ "Thomas Meeks",
"Gregg Pollack",
"Christine Wong",
"Dan McGaw" ]; modifiedNames.map(function(cell){
alert("Yo, "+cell)
});
var puzzlers = [
function ( a ) { return 3*a - 8; },
function ( a ) { return (a+2) * (a+2) * (a+2); },
function ( a ) { return a * a - 9; },
function ( a ) { return a % 4; }
];

[Javascript] Using map() function instead of for loop的更多相关文章

  1. 你了解javascript中的function吗?(1)

    上一篇文章中 介绍了function在javascirpt作为一等公民所担任的重要责任,在不同 的上下文中它担任着不同的角色,在对象内部它可以是函数,同时又能充当名字空间,不仅如此所有的functio ...

  2. JavaScript之Map对象

    前言 工欲善其事,必先利其器.这是一款以前在前端项目中没有使用过的.有趣的对象,咱来看看如何使用~ 并非arrayObj.map(function) //arrayObj.map与arrayObj.f ...

  3. JavaScript中map函数和filter的简单举例

    JavaScript的数组迭代器函数map和filter,可以遍历数组时产生新的数组,和python的map函数很类似 1> filter是满足条件的留下,是对原数组的过滤:2> map则 ...

  4. JavaScript Array.map

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

  5. JavaScript之map与parseInt的陷阱

    问题来源 ​ 这个问题的来源是学习廖雪峰老师JS教程.问题如下:小明希望利用map()把字符串变成整数,他写的代码很简洁: 'use strict'; var arr = ['1', '2', '3' ...

  6. JavaScript实现Map、Reduce和Filter

    1. [代码][JavaScript]代码     <script type="text/javascript">// 函数式编程:// 描述我们要做什么,而不是我们如 ...

  7. javascript自定义Map对象

    javascript定义map对象开发前端组件的重要性就不过多阐述了,直接参考以下案例即可 <script type=text/javascript charset=utf-8> func ...

  8. JavaScript Array map() 方法

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

  9. JavaScript 中 map、foreach、reduce 间的区别

    一直对map.foreach.reduce这些函数很是生疏,今天看underscorejs时好好研究了一下,一研究我就更懵了,这不是一样嘛,都是遍历,所以我就去知乎找了一下,整理出了比较好的几个说法. ...

随机推荐

  1. 使用Java创建Excel,并添加内容

    使用Java创建Excel,并添加内容 一.依赖的Jar包 jxl.jar,使用jxl操作Excel Jxl是一个开源的Java Excel API项目,通过Jxl,Java可以很方便的操作微软的Ex ...

  2. 牛可乐发红包脱单OI赛 C 小可爱表白

    打个暴力查一下OEIS,5min做完 出题人一开始把式子打错了,一开始的式子的结果为$n * (n + 3) * 2^{n - 3}$ 我们考虑化式子 首先考虑 $\sum\limits_{j = 1 ...

  3. bzoj 3283 扩展BSGS + 快速阶乘

    T2  扩展BSGS T3 快速阶乘 给定整数n,质数p和正整数c,求整数s和b,满足n! / pb = s mod pc 考虑每次取出floor(n/p)个p因子,然后将问题转化为子问题. /*** ...

  4. Treap树理解

    title: Treap树理解 comments: true date: 2016-10-06 07:57:37 categories: 算法 tags: Treap树 树 Treap树理解 简介 随 ...

  5. Codeforces Round #280 (Div. 2) A. Vanya and Cubes 水题

    A. Vanya and Cubes time limit per test 1 second memory limit per test 256 megabytes input standard i ...

  6. Oracle常见的查询代码

    /** * 分页查询 */ int currentPage=3;//当前页码 int pageSize=5;//每页的记录条数 String sql=" select * from &quo ...

  7. oracle开发学习篇之集合运算符以及集合异常捕获

    --取出集合;长度 declare type list_nested ) not null; v_all list_nested := list_nested('a','b','c','d','c', ...

  8. 自动化运维之 ~cobbler~

    一 .Cobbler简介 Cobbler是一个快速网络安装linux的服务,而且在经过调整也可以支持网络安装windows.该工具使用python开发,小巧轻便(才15k 行python代码),使用简 ...

  9. Tasker to stop Poweramp control for the headset while there is an incoming SMS - frozen

    If you usually like to use Poweramp or any other media player to enjoy the music with headset plugge ...

  10. 5V and 3V Level Translators

    http://www.daycounter.com/Circuits/Level-Translators/Level-Translators.phtml Interfacing 5V and 3V l ...