Skip to content

Instantly share code, notes, and snippets.

@K-Vishwak
Created January 17, 2022 15:46
Show Gist options
  • Save K-Vishwak/eb3a2416372f6bfd48fd2a7be46d9b73 to your computer and use it in GitHub Desktop.
Save K-Vishwak/eb3a2416372f6bfd48fd2a7be46d9b73 to your computer and use it in GitHub Desktop.
const str = 'Welcome to vkglobal just code';
// copies entire string.
str.slice();
> 'Welcome to vkglobal just code'
// between indexes. Count spaces too.
str.slice(11,19);
> 'vkglobal'
// index greater than string length;
str.slice(30);
> ''
// offset from last index. e -> -1, d -> -2 ...
str.slice(-9);
> 'just code'
// negative range.
str.slice(-9, -5);
> 'just'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment