您好,登錄后才能下訂單哦!
var data = [
{id: 1, name: "張三", age: 29, constellation: "水瓶座"},
{id: 2, name: "李四", age: 17, constellation: "射手座"},
{id: 3, name: "王五", age: 34, constellation: "白羊座"},
{id: 4, name: "趙六", age: 18, constellation: "金牛座"},
{id: 5, name: "孫七", age: 22, constellation: "巨蟹座"},
{id: 6, name: "周八", age: 25, constellation: "摩羯座"},
{id: 7, name: "吳九", age: 31, constellation: "雙子座"}
]
如何取出所有星座并組成一個新的數組?
var newData = data.map(function(v){
return v.constellation
})
console.log(newData)
(7)?["水瓶座", "射手座", "白羊座", "金牛座", "巨蟹座", "摩羯座", "雙子座"]
注意:map方法有返回值 forEach沒有返回值
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。