Skip to content

Instantly share code, notes, and snippets.

@rickyhaswifi
Created September 20, 2019 22:17
Show Gist options
  • Save rickyhaswifi/a390301dea3b6c83cb3ffd9bd3b90d43 to your computer and use it in GitHub Desktop.
Save rickyhaswifi/a390301dea3b6c83cb3ffd9bd3b90d43 to your computer and use it in GitHub Desktop.
Extract ID from user input in JS
const youtubeID = (link) => link.slice(link.lastIndexOf('=')+1);
console.log(youtubeID('https://www.youtube.com/watch?v=N65RvNkZFGE'));
const shortLink = (short) => short.slice(short.lastIndexOf('e/')+2);
console.log(shortLink('https://youtu.be/N65RvNkZFGE'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment