CodeWithHarry / Sigma-Web-Dev-Course

Source Code for Sigma Web Development Course
6.27k stars 1.93k forks source link

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

Open LomashB opened 4 months ago

LomashB commented 4 months ago

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);