Answers for "slice Examples¶"

0

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
Posted by: Guest on June-14-2021
0

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
Posted by: Guest on June-14-2021

Code answers related to "Javascript"

Browse Popular Code Answers by Language