js数组中有map方法,就是专门做这个的。如下:
var list = [{"name":"zhangsan",{"name":"lisi"}}];
var get_name = function(x) {
return x.name;
}
var new_list = list.map(add_one);
将 get_name 函数放到里面.
var list = [{"name":"zhangsan",{"name":"lisi"}}];
var new_list = list.map(function(x){
return x.name;
});
使用lambda表达式:
var list = [{"name":"zhangsan",{"name":"lisi"}}];
var new_list = list.map(x => x.name);
网友评论