1

I want to parse subtitles from srt files (which I already did by following this Parse a SRT file with jQuery Javascript). But now I do want to display just one subtitle at the time (only text), I have tried with:

    document.body.innerHTML += subtitles[cont].text;
    var randomItem = t[Math.floor(Math.random()*t.length)];
    document.body.innerHTML = randomItem; 

but the problem with it is that I get only one letter at the time, good thing is it random but I do want the whole subtitle. If I console.log subtitles[cont].text I get this

And I can see they are separated. But I can't understand how to get only one of the two.

TylerH
  • 20,799
  • 66
  • 75
  • 101
Nicoletta
  • 57
  • 10
  • What is the variable `t`? – twharmon Apr 10 '20 at 12:47
  • subtitles[cont].text = t; – Nicoletta Apr 10 '20 at 12:48
  • Please update entire code, Seems parameters are missing – xdeepakv Apr 10 '20 at 12:49
  • And for info, String is also Array line structure, so u can get text by index. May be by mistake u working on text rather than the array. – xdeepakv Apr 10 '20 at 12:50
  • The code is basically the same as the one in the link, the only thing that's changing are the subtitles and that (ending) part mentioned above – Nicoletta Apr 10 '20 at 12:52
  • It's very confusing. Please show more code. If t is what you say it is then, line 2 is choosing a random letter out of the text in subtitles[cont].text. But you are saying this is NOT what you want? Are you sure you don't want to just index subtitles[] ? Please show the line that sets the variable t. – Rob L Apr 10 '20 at 14:00

1 Answers1

0

Does this fix it?

document.body.innerHTML += subtitles[cont].text;
var randomItem = subtitles[Math.floor(Math.random()*subtitles.length)];
document.body.innerHTML = randomItem.text;
twharmon
  • 4,153
  • 5
  • 22
  • 48