Javascript 1.6 数组新增方法介绍之 map() – 示例

将所有的数组元素转换为大写:

代码:
var strings = ["hello", "Array", "WORLD"];
function makeUpperCase(v)
{
	return v.toUpperCase();
}
var uppers = strings.map(makeUpperCase);
// uppers is now ["HELLO", "ARRAY", "WORLD"]
// strings is unchanged
结果: