1

Okay, so I'm trying to work on getting a few songs to play. I have them in an array so I could get them to play in a random order. Is there a way where I could take out an .mp3 after it is played?

var thisHoldsThePaths = ["music/badapple.mp3", "music/heartbreak.mp3","music/caramell.mp3"];

var indexNumber = Math.floor(Math.random() * (thisHoldsThePaths.length));

var audio = new Audio(thisHoldsThePaths[indexNumber]);
audio.load();
audio.play();

That's what I have so far.

Ol' Dally
  • 11
  • 1
  • 1
    `splice()` would do that, but it would probably be just as easy to just [shuffle](http://stackoverflow.com/questions/6274339/how-can-i-shuffle-an-array-in-javascript) the array and [`pop`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/pop) of the end etc. – adeneo Sep 25 '16 at 14:52
  • 1
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/splice – Teemu Sep 25 '16 at 14:54

0 Answers0