你好嗎?現(xiàn)在,我正在用 Javascript 學(xué)習(xí)數(shù)組。我已經(jīng)完成了一個(gè)將數(shù)組內(nèi)容顯示到 HTML 文件中的函數(shù),但我只收到“未定義”。首先,我嘗試修改“contenido”內(nèi)部的代碼,但我只將“字符”接收到0位置,例如:contenido += "<div id=d"+posicion+">Titulo: " +系列標(biāo)題[0]。它給我返回了“D”,德克斯特。我究竟做錯(cuò)了什么?這是我的代碼。/*Creating a class to structure the information of a TV show by saving the title, theme, array with the main actors and saving the favorite actor in the array.*/class SerieTV { constructor (titulo, tematica, actoresPrincipales){ var arrayActores = new Array(); this.titulo=titulo; this.tematica=tematica; this.actores=actoresPrincipales;/* Adding a function to generate a random favorite actor.*/ this.generaActorFavorito = function(){ var long = actoresPrincipales.length; let calc = Math.floor(Math.random()*(long)); arrayActores = actoresPrincipales[calc]; console.log(arrayActores); } }}/* Creating 3 series, the 1st with 2 actors, 2nd with 3 and 3rd with 4. Later, adding it to a new array called "total_series."*/var show01= new SerieTV('Dexter ', 'Drama ', ['Michael C Hall ' ,'Jennifer Carpenter']);show01.generaActorFavorito();var show02 = new SerieTV('Samurai Gourmet' , 'Cocina' , ['Naoto Takenaka' ,'Tetsuji Tamayama' , 'Honami Suzuki '] );show02.generaActorFavorito();var show03 = new SerieTV ('Breaking Bad ', 'Drama ', ['Aaron Paul ','Bryan Cranston ', 'RJ Mitte ', 'Anna Gunn ']); show03.generaActorFavorito();console.log("-------------------------");var total_series = new Array();total_series.push(show01);total_series.push(show02);total_series.push(show03);console.log(total_series);console.log("-------------------------");
如何正確顯示我的數(shù)組?初學(xué)者里面
富國滬深
2023-06-29 22:46:31