slice examples c2 b6

Solutions on MaxInterview for slice examples c2 b6 by the best coders in the world

showing results for - "slice examples c2 b6"
Jessica
18 Jun 2016
1/*Use string concatenation and two slice() methods to print
2'JS' from 'JavaScript'.*/
3
4let language = 'JavaScript';
5console.log(language.slice(0,1)+language.slice(4,5));
6
7//JS
Felix
06 Mar 2020
1//The general syntax for this method is:
2
3stringName.slice(i, j);
4/*Given a starting index i and an optional ending index j, return the
5substring consisting of characters from index i through index j-1. 
6If the ending index is ommitted, the returned substring includes all
7characters from the starting index through the end of the string.*/
8
9"LaunchCode".slice(0, 6);
10
11"LaunchCode".slice(6);
12
13//Launch
14//Code
15
16
17/*On some websites, the portion of an email address before the @ symbol
18is used as a username. We can extract this portion of an email address
19using slice in conjunction with indexOf.*/
20
21let input = "fake.email@launchcode.org";
22let atIndex = input.indexOf("@");
23let username = input.slice(0, atIndex);
24console.log(username);
25
26//fake.email