亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何正確顯示我的數組?初學者里面

如何正確顯示我的數組?初學者里面

富國滬深 2023-06-29 22:46:31
你好嗎?現在,我正在用 Javascript 學習數組。我已經完成了一個將數組內容顯示到 HTML 文件中的函數,但我只收到“未定義”。首先,我嘗試修改“contenido”內部的代碼,但我只將“字符”接收到0位置,例如:contenido += "<div id=d"+posicion+">Titulo: " +系列標題[0]。它給我返回了“D”,德克斯特。我究竟做錯了什么?這是我的代碼。/*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("-------------------------");
查看完整描述

2 回答

?
幕布斯6054654

TA貢獻1876條經驗 獲得超7個贊

要訪問類的成員,請使用點表示法語法。

contenido += "<div id=d"+posicion+">Titulo: "+serie.titulo+"<br> Temática: "+serie.tematica+" <br> Actor Favorito: "+serie.actoresPrincipales+" <br> Actores: "+serie.actores+" <br><br>";

generaActorFavorito另外,在這個語句的方法中,arrayActores = actoresPrincipales[calc]您將一個數組重新分配為一個沒有意義的值,您可以簡單地執行var arrayActores;而不是var arrayActores = new Array();


查看完整回答
反對 回復 2023-06-29
?
慕慕森

TA貢獻1856條經驗 獲得超17個贊

好的,問題解決了。我解決了刪除方括號的問題。謝謝你們??!

contenido += "<div id=d"+posicion+">Titulo: "+serie.titulo+"<br> Temática: "+serie.tematica+" <br> Actor Favorito: "+serie.actoresPrincipales+" <br> Actores: "+serie.actores+" <br><br>";



查看完整回答
反對 回復 2023-06-29
  • 2 回答
  • 0 關注
  • 182 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號