Slice Example
/*Use string concatenation and two slice() methods to print
'JS' from 'JavaScript'.*/
let language = 'JavaScript';
console.log(language.slice(0,1)+language.slice(4,5));
//JS
Slice Example
/*Use string concatenation and two slice() methods to print
'JS' from 'JavaScript'.*/
let language = 'JavaScript';
console.log(language.slice(0,1)+language.slice(4,5));
//JS
slice Examples¶
//The general syntax for this method is:
stringName.slice(i, j);
/*Given a starting index i and an optional ending index j, return the
substring consisting of characters from index i through index j-1.
If the ending index is ommitted, the returned substring includes all
characters from the starting index through the end of the string.*/
"LaunchCode".slice(0, 6);
"LaunchCode".slice(6);
//Launch
//Code
/*On some websites, the portion of an email address before the @ symbol
is used as a username. We can extract this portion of an email address
using slice in conjunction with indexOf.*/
let input = "[email protected]";
let atIndex = input.indexOf("@");
let username = input.slice(0, atIndex);
console.log(username);
//fake.email
Copyright © 2021 Codeinu
Forgot your account's password or having trouble logging into your Account? Don't worry, we'll help you to get back your account. Enter your email address and we'll send you a recovery link to reset your password. If you are experiencing problems resetting your password contact us