[Javascript] map Array method

Map is a method for javascript Array.

It calls a defined callback function on each element of an array, and returns an array that contains the results.
map函数对数组中每个元素调用一个已定义的回调方法。

yourArray.map(callbackfn[, thisArg])
    Parameters : 参数
  • yourArray
    Required. An array object. 数组(必须)
  • callbackfn
    Required. A function that accepts up to three arguments. The map method calls the callbackfn function one time for each element in the array. 回调函数,最多可接受三个参数(必须)
  • thisArg
    Optional. An object to which the this keyword can refer in the callbackfn function. If thisArg is omitted, undefined is used as the this value. 关联到回调函数的一个对象(可选)
    Return : 返回值
    A new array in which each element is the callback function return value for the associated original array element. 一个重新生成的数组

    Example : 例子
[1, 2, 3].map(function(num) {
  return num*10;
});

Ref. MSDN

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s