Is it possible to preload sounds into an array with p5 sound?

I am using p5.js in a rather unconventional way where having sounds in an array would help a lot. Is it possible to do something like,

function preload(){
	for(i = 0; i < songLocations.length; i++){
		p5SongList[i] = loadSound(songLocations[i])
	}
}

or is this the only current way to load sounds,

function preload(){
	sound = loadSound(songList[0]);
	sound1 = loadSound(songList[1]);
	sound2 = loadSound(songList[2]);
	sound3 = loadSound(songList[3]);
	sound4 = loadSound(songList[4]);
}

Thanks!

Yes it is! Haven’t you tried that out yet? :neutral_face:

I did try this, but p5SongList[0] was undefined… I forgot to initiate the array in global scope :upside_down_face:

The below does indeed work!

var p5SongList = []

function preload(){
	for(i = 0; i < songLocations.length; i++){
		p5SongList[i] = loadSound(songLocations[i])
	}
}

function draw(){
	if(!p5SongList[0].isPlaying()){
		p5SongList[0].play();
	}
}