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

194
Visualizações
Storing and adding songs in JavaScript

I want to store 10 songs statically in JavaScript and add more songs dynamically via the web application.
At the same time, I would like to show 5 random songs in the list using the button. I like a search field. Can anyone give tips and hints?

about 4 years ago · Juan Pablo Isaza
2 Respostas
Responde à pergunta

0

Having 10 song on on client side is bad idea because each time you load webpage that 10 songs need to be loaded on users browser. It is possible user may not listen all of them but just listen 1 or 2.

Best approach is you have your best 10 songs list available, once user play some song you stream it right away.

You can find sample codes from git projects just search for "git : music player"

about 4 years ago · Juan Pablo Isaza Relatório

0

// Predefined Songs
const songs = [
  'song 1',
  'song 2',
  'song 3',
  'song 4',
  'song 5',
  'song 6',
  'song 7',
  'song 8',
  'song 10',
];
// Parent Element of list of songs
const ul = document.querySelector('ul');

// Add Songs
songs.push('song');

// Display It
const displaySongs = () => {
  const randomSongs = [];
  for (let i = 0; i < 5; i++) {
    let songIndex = Math.floor(Math.random() * songs.length);
    if (!randomSongs.includes(songs[songIndex])) {
      randomSongs.push(songs[songIndex]);
    } else {
      i--;
    }
  }
  ul.innerHTML = randomSongs.map((song) => `<li>${song}</li>`).join('');

};
displaySongs();

about 4 years ago · Juan Pablo Isaza 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