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. Ubuntu18.04 创建桌面快捷方式

    一.基本概念 Linux 系统中的Desktop Entry 文件以desktop为后缀名.Desktop Entry 文件是 Linux 桌面系统中用于描述程序启动配置信息的文件.  进入/usr/ ...

  2. 4040 EZ系列之奖金

    4040 EZ系列之奖金 时间限制: 1 s 空间限制: 64000 KB 题目等级 : 钻石 Diamond   题目描述 Description 由于无敌的WRN在2015年世界英俊帅气男总决选中 ...

  3. HDU.2899.Strange fuction(牛顿迭代)

    题目链接 \(Description\) 求函数\(F(x)=6\times x^7+8\times x^6+7\times x^3+5\times x^2-y\times x\)在\(x\in \l ...

  4. windows提权exp列表

    漏洞列表 #Security Bulletin #KB #Description #Operating System CVE-2017-0213 [Windows COM Elevation of P ...

  5. Git_工作区和暂存区

    Git和其他版本控制系统如SVN的一个不同之处就是有暂存区的概念. 先来看名词解释. 工作区(Working Directory):就是你在电脑里能看到的目录,比如我的learngit文件夹就是一个工 ...

  6. Ubuntu16.04中安装stlink驱动

    系统环境: Vmware12, Ubuntu16.04 Stlink version:v1.4.0 一.安装依赖包: sudo apt-get install libusb-1.0 sudo apt- ...

  7. SpringBoot无法启动,Process finished with exit code 0

    1.排查yml和properties文件是否配置错误 2.排查POM引入的包

  8. Win7 开启显示快速启动工具栏,发送到快速启动右键菜单

    开启Win7快速启动栏 许多网友一定记得在 Windows 7 之前的 Windows 系统都有个快速启动(quick launch)区域. 比如 IE 浏览器.Windows Media Playe ...

  9. SpringMVC怎么获取前台传来的数组

    var tollerlist = new Array(); for(var k in objToller){ tollerlist.push(k); } $.ajax({ type:"pos ...

  10. 分布式中使用redis进行session共享

    摘要 在asp.net web中,session经常用来存储当前用户信息,或者通过session进行登录权限的验证.如果是一台服务器,session的使用没问题,如果使用nginx等实现反向代理,将站 ...