我是javascript的初学者所以我感谢任何帮助/建议.
我的问题在于我正在试图弄清楚如何在times []数组中的项之间添加空格,该数组包含每个电影对象的放映时间值.我试图用逗号分隔(","),但这不起作用.当我尝试拆分("pm")时有效.我还想出了一种在showtimes值中添加空间的方法,但我认为必须有更好的方法来实现它.有什么想法吗?谢谢!
window.onload = init;
function Movie(title, year, showtimes) {
this.title = title;
this.year = year;
this.showtimes = showtimes;
}
function init() {
var darkKnight = new Movie("The Dark Knight Rises", "2012", ["1pm,", "2pm,", "3pm,"]);
var takeThisWaltz = new Movie ("Take This Waltz", "2012", ["4pm", "5pm","6pm"]);
var watchmen = new Movie("Watchmen", "2009", ["7pm","8pm","9pm"]);
var movieList = [darkKnight, takeThisWaltz, watchmen]
for(var i = 0; i < movieList.length; i++) {
var theObj = movieList[i];
var times = [movieList[i].showtimes]
for(var j = …Run Code Online (Sandbox Code Playgroud)