0006 added[string slicing]
This commit is contained in:
29
js/index.js
29
js/index.js
@@ -199,4 +199,31 @@ x = Math.SQRT2; //sqrt(2)
|
||||
console.log(x);
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//https://youtu.be/8dWL3wF_OMw?t=2220
|
||||
//12.Useful string methods
|
||||
let userName = "WickedJack99"
|
||||
console.log(userName.length); // get length of string
|
||||
console.log(userName.charAt(0)); // get charAt x of string starting index is 0
|
||||
console.log(userName.indexOf("c")); // get first occurence-index of letter x
|
||||
console.log(userName.lastIndexOf("c")); // get last occurence-index of letter x
|
||||
console.log(userName.trim()); // removes whitespaces
|
||||
console.log(userName.toUpperCase()); // changes whole string to upper case
|
||||
console.log(userName.toLowerCase()); // changes whole string to lower case
|
||||
let phoneNumber = "0123 335321";
|
||||
console.log(phoneNumber.replaceAll("3", "0")); // replaces all 3s of phoneNumber by 0
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//13.String-slicing
|
||||
//Extracts a section of a string and returns a new string without modifying the original string.
|
||||
let omName = "Wicked Jack99";
|
||||
let firstName2;
|
||||
let lastName2;
|
||||
//firstName2 = omName.slice(0,6);
|
||||
//lastName2 = omName.slice(7);
|
||||
firstName2 = omName.slice(0, omName.indexOf(" "));
|
||||
lastName2 = omName.slice(omName.indexOf(" ") + 1);
|
||||
console.log(firstName2);
|
||||
console.log(lastName2);
|
||||
//--------------------------------------------------------------------------------------------------------------
|
||||
|
||||
//14.Method chaining
|
||||
//https://youtu.be/8dWL3wF_OMw?t=3554
|
||||
Reference in New Issue
Block a user