Empresas
Empregos
  • Sobre nós
  • Soluções
    • Publicação de vagas
      Publique sua vaga e receba candidatos qualificados em 48h.
    • Avaliações de candidatos
      Mais de 500 testes técnicos e psicológicos, mais anti-fraude.
    • Headhunting
      Busca executiva personalizada do início ao fim.
    • Folha de Pagamento + EOR
      Dispersão de folha e EOR em mais de 15 países da LATAM.
  • Preços
  • Empregos

0

107
Visualizações
How to loop an array inside another array in Javascript?

Given this script

<script>
var sentences= 
[
 ['journey27.mp4', 
  [
    [1, 2],
    [5, 7]
  ]
 ],
 ['journey28.mp4', 
  [
    [10, 12],
    [13, 17],
    [25, 36]
  ]
 ],
 ['journey30.mp4', 
  [
    [13, 15],
    [15, 19]
  ]
 ]
];

function playVideo(myUrl, startTime, endTime) { 
  console.log(`Playing ${myUrl} from ${startTime} to ${endTime}`);
} 
function myLoop(){
//what should I fill in here?
}
</script>

I want to print out this result:

Playing 'journey27.mp4' from 1 to 2
Playing 'journey27.mp4' from 1 to 2
Playing 'journey27.mp4' from 1 to 2

Playing 'journey27.mp4' from 5 to 7
Playing 'journey27.mp4' from 5 to 7
Playing 'journey27.mp4' from 5 to 7

Playing 'journey28.mp4' from 10 to 12
Playing 'journey28.mp4' from 10 to 12
Playing 'journey28.mp4' from 10 to 12

Playing 'journey28.mp4' from 13 to 17
Playing 'journey28.mp4' from 13 to 17
Playing 'journey28.mp4' from 13 to 17

Playing 'journey28.mp4' from 25 to 36
Playing 'journey28.mp4' from 25 to 36
Playing 'journey28.mp4' from 25 to 36

Playing 'journey30.mp4' from 13 to 15
Playing 'journey30.mp4' from 13 to 15
Playing 'journey30.mp4' from 13 to 15

Playing 'journey30.mp4' from 15 to 19
Playing 'journey30.mp4' from 15 to 19
Playing 'journey30.mp4' from 15 to 19

Note: each line of the subarray should be played 3 times then it moves to the next line.

How can I fill in myLoop function to print out the above result?

about 4 years ago · Santiago Trujillo
1 Respostas
Responde à pergunta

0

You can try this approach

var data = [
  ['journey27.mp4',
    [
      [1, 2],
      [5, 7]
    ]
  ],
  ['journey28.mp4',
    [
      [10, 12],
      [13, 17],
      [25, 36]
    ]
  ],
  ['journey30.mp4',
    [
      [13, 15],
      [15, 19]
    ]
  ]
];

function playVideo(myUrl, startTime, endTime) {
  console.log(`Playing ${myUrl} from ${startTime} to ${endTime}`);
}

function myLoop(sentences, lineCount) {
  for (const sentence of sentences) {
    const [video, timers] = sentence //extract video url and the timer array
    for (const timer of timers) {
      const [startTime, endTime] = timer //extract start time and end time in each timer
      for (let i = 0; i < lineCount; i++) {
        playVideo(video, startTime, endTime) //console.log for each line
      }
    }
  }
}

const lineCount = 3 //will print 3 times
myLoop(data, lineCount)

about 4 years ago · Santiago Trujillo Relatório
Responde à pergunta
Encontrar trabalhos remotos

Descubra a nova forma de encontrar um emprego!

melhores empregos
Principais categorias de trabalho
Empresas
Postar vaga Preços Comercial
Jurídico
Termos e Condições Política de privacidade
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomende algumas ofertas para mim
Preciso de ajuda