[Javascript] Using map() function instead of for loop
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的更多相关文章
- 你了解javascript中的function吗?(1)
上一篇文章中 介绍了function在javascirpt作为一等公民所担任的重要责任,在不同 的上下文中它担任着不同的角色,在对象内部它可以是函数,同时又能充当名字空间,不仅如此所有的functio ...
- JavaScript之Map对象
前言 工欲善其事,必先利其器.这是一款以前在前端项目中没有使用过的.有趣的对象,咱来看看如何使用~ 并非arrayObj.map(function) //arrayObj.map与arrayObj.f ...
- JavaScript中map函数和filter的简单举例
JavaScript的数组迭代器函数map和filter,可以遍历数组时产生新的数组,和python的map函数很类似 1> filter是满足条件的留下,是对原数组的过滤:2> map则 ...
- JavaScript Array.map
Array.prototype.map() History Edit This article is in need of a technical review. Table of Contents ...
- JavaScript之map与parseInt的陷阱
问题来源 这个问题的来源是学习廖雪峰老师JS教程.问题如下:小明希望利用map()把字符串变成整数,他写的代码很简洁: 'use strict'; var arr = ['1', '2', '3' ...
- JavaScript实现Map、Reduce和Filter
1. [代码][JavaScript]代码 <script type="text/javascript">// 函数式编程:// 描述我们要做什么,而不是我们如 ...
- javascript自定义Map对象
javascript定义map对象开发前端组件的重要性就不过多阐述了,直接参考以下案例即可 <script type=text/javascript charset=utf-8> func ...
- JavaScript Array map() 方法
语法: array.map(function(currentValue,index,arr), thisValue) currentValue:必须.当前元素的值index:可选.当期元素的索引值ar ...
- JavaScript 中 map、foreach、reduce 间的区别
一直对map.foreach.reduce这些函数很是生疏,今天看underscorejs时好好研究了一下,一研究我就更懵了,这不是一样嘛,都是遍历,所以我就去知乎找了一下,整理出了比较好的几个说法. ...
随机推荐
- [Agc011F] Train Service Planning
[Agc011F] Train Service Planning 题目大意: 有n+1个车站,n条轨道,第i条轨道联通i-1和i车站,通过它要花a[i]时间,这条轨道有b[i]=1或2条车道,也就是说 ...
- 【线段树】【扫描线】Petrozavodsk Winter Training Camp 2018 Day 5: Grand Prix of Korea, Sunday, February 4, 2018 Problem A. Donut
题意:平面上n个点,每个点带有一个或正或负的权值,让你在平面上放一个内边长为2l,外边长为2r的正方形框,问你最大能圈出来的权值和是多少? 容易推出,能框到每个点的 框中心 的范围也是一个以该点为中心 ...
- Substring with Concatenation of All Words 题解
题意 You are given a string, s, and a list of words, words, that are all of the same length. Find all ...
- Codeforces Round #259 (Div. 1) A. Little Pony and Expected Maximum 数学公式结论找规律水题
A. Little Pony and Expected Maximum Time Limit: 1 Sec Memory Limit: 256 MB 题目连接 http://codeforces.c ...
- Apache的443端口被占用解决方法(转)
今天想做PHP程序,结果启动Apache的时候控制台报443端口被占用.原因是我的虚拟机VMware占用443端口用于连接远程服务器的.其实出现这些状况很正常.因为不同的程序很有可能同时需要一个端口维 ...
- 浅析OpenGL光照
浅析OpenGL光照 之前从来都没有涉及光照的内容,心想只要能通过常规的方法渲染出几何体甚至是模型就可以了,然而没有光照的日子注定是苦涩的,因为仅凭几何体和模型的颜色无法达到真是渲染的效果,在实际中有 ...
- 关于Hyper-V备份的四大注意事项
尽管Hyper-V备份相对简单,但备份管理员仍需注意四大问题.这四方面的问题在创建备份时可能不太重要,但在备份恢复时影响甚大. 1.对于虚拟机来说不仅意味着虚拟磁盘 就目前来看,企业在执行Hyper- ...
- OPC and .NET
Note: recent OPC standards, including Unified Architecture (UA) and Express Interface (Xi) were desi ...
- 报错:该字符串未被识别为有效的DateTime
报错:该字符串未被识别为有效的DateTime □ 背景 前端的搜索条件中包含关于时间的字符串,由jquery ui的datepicker产生时间字符串. 服务端对时间做了一次转换:DateTime. ...
- MVC自定义编辑视图,DateTime类型属性显示jQuery ui的datapicker
实现的效果为:在编辑视图中,对DateTime类型的属性,显示jQuery UI的datepicker.效果如下: Student.cs public class Student { ...