// slice() extracts a section of a string // and returns it as a new string, // without modifying the original string let fullName = "Snoop Dogg"; let firstName; let lastName; //firstName = fullName.slice(0, 3); //lastName = fullName.slice(4); firstName = fullName.slice(0, fullName.indexOf(" ")); lastName = fullName.slice(fullName.indexOf(" ") + 1); console.log(firstName); console.log(lastName);
It would be the same. The length of the name doesn't matter since you would be using indexOf to set your slice values before and after the space. firstName = fullName.slice(0, fullName.indexOf(" ")); lastName = fullName.slice(fullName.indexOf(" ") + 1);
// slice() extracts a section of a string
// and returns it as a new string,
// without modifying the original string
let fullName = "Snoop Dogg";
let firstName;
let lastName;
//firstName = fullName.slice(0, 3);
//lastName = fullName.slice(4);
firstName = fullName.slice(0, fullName.indexOf(" "));
lastName = fullName.slice(fullName.indexOf(" ") + 1);
console.log(firstName);
console.log(lastName);
Practicing...
let fullName = "Spicy Spy";
let lastName;
//firstName = fullName.slice(0,9);
//lastName = fullName.slice(10);
firstName = fullName.slice(0, fullName.indexOf(" "));
lastName = fullName.slice(fullName.indexOf(" ")+ 1);
console.log(firstName);
console.log(lastName);
Thanks bro! I really like your style of explaining things, easy to understand for me as a beginner.
Great teacher as always, my friend
Thank you every video is practical 🤗
The Bro we needed!
Thanks, Bro!
Thanks!
That was spicy 🔥
thankYouBro.slice();
Thanks bro
Ily
👏
what if the name is long? what would be the syntax?
It would be the same. The length of the name doesn't matter since you would be using indexOf to set your slice values before and after the space.
firstName = fullName.slice(0, fullName.indexOf(" "));
lastName = fullName.slice(fullName.indexOf(" ") + 1);
How much do you charge for tuition?
SQRRRRT for the algorithm
squirt? sus
👊🏽
Wubba Lubba Dub-Dub, For the algorithm!
random comment
Fredhhrrggv ❤