我的任務(wù)是從適合特定類別的數(shù)據(jù)集中打印所有個人的名字;但是,數(shù)據(jù)集是一個對象數(shù)組,它以字符串形式提供全名,例如:var dataSet = [ { "name": "John Doe", "age": 60, "math": 97, "english": 63, "yearsOfEducation": 4 }, { "name": "Jane Doe", "age": 55, "math": 72, "english": 96, "yearsOfEducation": 10 }]我不能使用除filter(),map()和reduce()之外的任何數(shù)組類型的內(nèi)置函數(shù)。我的代碼的最后一塊(從對象數(shù)組“ dataSet”中獲取名稱)如下所示:var youngGoodMath = dataSet.filter(function(person){ return person.age < avgAge && person.math > avgMath; }); var yGMname = youngGoodMath.map(function (person){ return person.name; });console.log(yGMname);產(chǎn)生一個看起來像這樣的字符串?dāng)?shù)組:["Jane Doe", "John Doe", "Harry Potter", "Hermione Granger"]我需要找到一種生產(chǎn)方式:["Jane", "John", "Harry", "Hermione"]我懷疑答案在于使用.forEach和.Split(),但是還無法破解...
如何在JavaScript中的數(shù)組內(nèi)拆分字符串(從全名中獲取名字)
梵蒂岡之花
2021-04-07 17:14:13