一、Array.from方法
array.from方法就是将一个类数组对象(具有length属性的对象)或者可遍历的对象转换成真正的数组
var user = [
{
id: 1,
name: "李四"
},
{
id: 2,
name: "张三"
},
{
id: 3,
name: "李五"
}
]
var userName = Array.from(user,({name})=>name);
console.log(userName); // ["李四", "张三", "李五"]
二、map方法
var userName = user.map((item)=>{
return item.name;
})
console.log(userName); // ["李四", "张三", "李五"]
三、foreach 方法
var userName = [];
user.forEach((item)=>{
userName.push(item.name);
})
console.log(userName); // ["李四", "张三", "李五"]
原文链接:https://blog.csdn.net/lyyo_cd/article/details/120483892