by @kodeazy
jquery get youtube video ID from URL using split function?
-
To get the
ID
of theYouTube
video fromURL
first we have to split theURL
and get the substring by neglecting other parameters//var url="https://www.youtube.com/watch?v=tQ0yjYUFKAE"; var url="https://www.youtube.com/watch?v=tQ0yjYUFKAE&list=TLGGoEoGU6P8wlUwNzA3MjAyMQ"; var totalString=url.split("v=")[1]; var longUrl=totalString.indexOf("&"); if(longUrl==-1){ console.log(totalString); } else{ console.log(totalString.substring(0,longUrl)) }
output
tQ0yjYUFKAE