Sigma-Web-Dev-Course icon indicating copy to clipboard operation
Sigma-Web-Dev-Course copied to clipboard

IMP: In Spotify clone #video-84 in finding index from array problem

Open LomashB opened this issue 1 year ago • 0 comments

in new version of node or maybe in all(because i encountered it) we can not find index with the code you wrote which is this:

let index = songs.indexOf(currentSong.src.split("/").slice(-1)[0]) if ((index + 1) < songs.length) { playMusic(songs[index + 1]) }

instead of that i suggest this for efficient and good finding because it always returns -1

suggested:

let songname = currentSong.src .split("/") .slice(-1)[0] .replaceAll("%20", " "); let index = songs.indexOf(songname); console.log(songs, index, songname, songs.length);

LomashB avatar Jun 30 '24 17:06 LomashB