Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

197
Views
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 answers
Answer question

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 Report

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 Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!