W3School TIY Editor
W3School 在线教程
改变方向
暗黑模式
运行代码
<!DOCTYPE html> <html> <body> <h1>JavaScript 数组</h1> <p>用旧数组中每个人的全名计算一个新数组:</p> <p id="demo"></p> <script> const persons = [ {firstname : "Malcom", lastname: "Reynolds"}, {firstname : "Kaylee", lastname: "Frye"}, {firstname : "Jayne", lastname: "Cobb"} ]; document.getElementById("demo").innerHTML = persons.map(getFullName); function getFullName(item) { return [item.firstname,item.lastname].join(" "); } </script> </body> </html>