map¶
Methods¶
- KISSY.map()¶
- Array KISSY.map (arr,fn[,context])创建一个新数组, 数组结果是在对每个原数组元素调用指定函数的返回值.
Parameters: - arr (Array) – 需要遍历的数组.
- fn (function) – 能够根据原数组当前元素返回新数组元素的函数.
- context (object) – 执行 fn 时的 this 值.
Returns: 返回符合根据指定函数调用得到新数组
Return type: Array
Note
原数组保持不变
例如:
function makePseudoPlural(single) { return single.replace(/o/g, "e"); } var singles = ["foot", "goose", "moose"]; var plurals = S.map(singles, makePseudoPlural); // => ["feet", "geese", "meese"] var a = S.map("Hello World",function(x) { return x.charCodeAt(0); }); // => [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100]