3 回答
TA贡献1856条经验 获得超11个赞
所以基本上你必须遍历数组并得到结果。
var hobbies = [
['Poker', 'VideoGames'],
['Board Games', 'Hiking', 'Rockclimbing'],
['Driving', 'Shopping']
];
const weekdays = ["Monday", "Tuesday", "Wednesday"];
for (i = 0; i < hobbies.length; i++) {
console.log("My hobbies on", weekdays[i], "are "+ hobbies[i].join() );
}
更新了错误处理代码。
function getWeekdayname(index){
const weekdays = ["Monday", "Tuesday", "Wednesday"];
if(index < weekdays.length){
return weekdays[i];
}
return 'X';
}
var hobbies = [
['Poker', 'VideoGames'],
['Board Games', 'Hiking', 'Rockclimbing'],
['Driving', 'Shopping'],
['Drivin 3g', 'Shoppin 6g']
];
for (i = 0; i < hobbies.length; i++) {
console.log("My hobbies on", getWeekdayname(i), "are "+ hobbies[i].join() );
}
添加回答
举报