What we will learn ↓
let myName = "vinod Thapa";
let myChannelName = 'Vinode Thapa';
//let ytName = new String("Thapa Techinical");
let ytName = 'Thapa Technical';
console.log(myName);
console.log(ytName);
How to find the length of a string.
let myName = "Vinod Thapa";
console.log(myName = length); // 11
Code Result Description
\' ' Single quote
\" " Double quote
\\ \ Backslash
let anySentence = "We are the so-called \"Vikings\" from the north.";
console.log(anySentence);
let anySentence = "We are the so-called 'Vikings' from the north.";
console.log(anySentence);
String.prototype.indexOf(searchValue[, fromIndex])
const myBioData = 'I am the Thapa Technical';
console.log(myBioData.indexOf("t", 6));
const myBioData = 'I am the Thapa Technical';
console.log(myBioData.lastIndexOf("t", 6)); // starts searching from 6th index
String.prototype.search(regexp)
const myBioData = 'I am the Thapa Technical';
let sData = myBioData.search("Technical");
console.log(sData); // 15
let str = "Apple, Banana, Kiwi, mango";
// let res = str.slice(0, 4); // "Appl"
let res = str.slice(7); // "Banana, Kiwi, mango"
// starts from 7th index to last.
Display only 280 characters of a string like the one used in Twitter.
let myTweets = "Lorem Impsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum. Why do we use it? ";
let myActualTweet = myTweets.slice(0, 280); // Lorem Impsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the 1500s, when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five cen
console.log(myActualTweet);
console.log(myActualTweet.length); // 280
let str = "Apple, Banana, Kiwi";
let res = str.substring(8, -2);
console.log(res); // Apple, B
let str = "Apple, Banana, Kiwi";
// let res = str.substr(0, 4); // "Appl"
// let res = str.substr(7, -2); // ""
let res = str.substr(-4); // "Kiwi" // extracting data from back
String.prototype.replace(searchFor, replaceWith)
let myBioData = 'I am Vinod Bahadur Thapa vinod';
let replacedString = myBioData.replace('vinod', 'Vinod');
console.log(replacedString); // I am Vinod Bahadur Thapa Vinod
console.log(myBioData); // I am Vinod Bahadur Thapa vinod
Points to remember ↓
let str = "HELLO WORLD";
console.log(str.charAt(9)); // L
let str = "HELLO WORLD";
console.log(str.charCodeAt(0));
Return the Unicode of the last character in a string.
let str = "HELLO WORLD";
console.log(str.charCodeAt(str.length - 1));
let str = "HELLO WORLD";
console.log(str[1]); // E
let myName = "vinod thapa";
console.log(myName.toUpperCase());
myName = "VINOD THAPA";
console.log(myName.toLowerCase());
let fName = "Vinod";
let lName = "Thapa";
console.log(fName + lName);
console.log(`${fName} ${lName}`);
console.log(fName.concat(lName));
console.log(fName.concat(" ", lName));
let str = " Hello WORLD ";
console.log(str.trim()); // "Hello World"
let txt = "a, b,c d,e"; // string
console.log(txt.split(",")); // Split on commas // [ "a", " b", "c d", "e" ]
console.log(txt.split(" ")); // Split on spaces // [ "a,", "b,c", "d,e" ]
console.log(txt.split("|")); // Split on pipe // [ "a, b,c d,e" ]