9
我是JavaScript的初學者,所以我非常感謝給出的任何幫助/建議。如何在數組項之間添加空格javascript
這裏我的問題是,我想弄清楚如何在times []數組中添加項目之間的空間,該數組包含每個電影對象的放映時間值。我試圖在逗號(「,」)分裂,但那是行不通的。當我嘗試在(「下午」)分裂工作。我也想出了一種在演出時間價值中增加空間的方法,但我認爲必須有更好的方式去實現它。有什麼想法嗎?謝謝!
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 = 0; j < times.length; j++) {
var str = times[i];
}
makeResult(); }
function makeResult() {
var list = document.getElementById("movieList");
var li = document.createElement("li");
li.innerHTML = "title: " + movieList[i].title + " year: " + movieList[i].year + " showtimes: " + times[0].toString().split(",");
list.appendChild(li); }
}
我犯了錯誤的保存我的聯合數組到另一個數組而不是字符串,它沒有失敗,但輸出不需要的逗號。 –