31
loading...
This website collects cookies to deliver better user experience
const firstName = 'Aya ';
const lastName = 'Bouchiha';
// 3 methods to concatenate two strings
console.log(firstName.concat(lastName)); // Aya Bouchiha
console.log(firstName + lastName); // Aya Bouchiha
console.log(`${firstName}${lastName}`); // Aya Bouchiha
const quote = "If you don't know where you are going, any road will get you there.";
console.log(quote.match(/you/g)) // [ "you", "you", "you" ]
const conversation = `Hi, I'm Aya Bouchiha\nHello, I'm John Doe, nice to meet you.`;
const matchedArrays = [...conversation.matchAll(/I'm\s(?<firstName>[a-zA-Z]+)\s(?<lastName>[a-zA-Z]+)/gi)];
console.log(matchedArrays[0])
for (let matchedArray of matchedArrays) {
const {firstName, lastName} = matchedArray['groups']
console.log(firstName, lastName)
}
[
"I'm Aya Bouchiha",
'Aya',
'Bouchiha',
index: 4,
input: "Hi, I'm Aya Bouchiha\nHello, I'm John Doe, nice to meet you.",
groups: [Object: null prototype] { firstName: 'Aya', lastName: 'Bouchiha' }
]
Aya Bouchiha
John Doe
const allLetters = 'abcdefghijklmnopqrstuvwxyz';
console.log(allLetters.split())
console.log(allLetters.split(''))
const emails = '[email protected],[email protected],[email protected]';
console.log(emails.split(','))
[ 'abcdefghijklmnopqrstuvwxyz' ]
[
'a', 'b', 'c', 'd', 'e', 'f',
'g', 'h', 'i', 'j', 'k', 'l',
'm', 'n', 'o', 'p', 'q', 'r',
's', 't', 'u', 'v', 'w', 'x',
'y', 'z'
]
[
'[email protected]',
'[email protected]',
'[email protected]'
]
const email = '[email protected]';
console.log(email.replace('@gmail.com', '')); // john.doe
console.log(email.replace(/@[a-z]+.[a-z]+/g, '')); // john.doe
const slug = '5-html-tags-that-almost-nobody-knows';
// 5 html tags that almost nobody knows
console.log(slug.replaceAll('-', ' '));
// 5 html tags that almost nobody knows
console.log(slug.replaceAll(/-/g, ' '));
const quote = 'A dream does not become reality through magic; it takes sweat, determination, and hard work';
console.log(quote.search('magic')); // 40
console.log(quote.search(/life/g)); // -1
const inputValue = ' Aya Bouchiha\t';
console.log(inputValue.trim()); // Aya Bouchiha
const address = 'Morocco, Rabat';
console.log(address.includes('Morocco'));// true
console.log(address.includes('morocco'));// false
console.log(address.includes('tanger')); // false
const name = 'AYa BoUCHIha';
console.log(name.toLowerCase()) // aya bouchiha
const name = 'AYa BoUCHIha';
console.log(name.toUpperCase()) // AYA BOUCHIHA
const turkishSentence = 'iskender kebap';
// ISKENDER KEBAP
console.log(turkishSentence.toLocaleUpperCase('en-us'));
// İSKENDER KEBAP
console.log(turkishSentence.toLocaleUpperCase('tr'))
const firstName = 'aya';
console.log(firstName.repeat(3)) // ayaayaaya
const fullName = 'Aya Bouchiha';
console.log(fullName.slice()) // Aya Bouchiha
console.log(fullName.slice(0,3)) // Aya
console.log(fullName.slice(4,fullName.length)) // Bouchiha
const fullName = 'Aya Bouchiha';
console.log(fullName.substr(0,3)) // Aya
console.log(fullName.substr(4,8)) // Bouchiha
0 <= index < string.length
const product = 'laptop';
console.log(product.charAt(3)) // t
console.log(product.charAt(10)) // ''
product.charAt("this is a string!") // l
console.log(product.charAt()) // l
const product = 'laptop';
console.log(`the character code of ${product.charAt(2)} is ${product.charCodeAt(2)}`)
// the character code of p is 112
const phoneNumber = '+212612342187';
console.log(phoneNumber.startsWith('+212')) // true
console.log(phoneNumber.startsWith('6',4)) // true
console.log(phoneNumber.startsWith('6',3)) // false
const address = 'tanger, Morocco';
console.log(address.endsWith('Morocco')); // true
console.log(address.endsWith('Canada')); // false
const gmail = '[email protected]';
const isGmail = gmail.endsWith('@gmail', gmail.length - 4)
console.log(isGmail); // true
console.log(String.fromCharCode(112)) // p
console.log(String.fromCharCode(105,106)) // ij
const quote = "every day may not be good... but there's something good in every day";
console.log(quote.indexOf('good')); // 21
console.log(quote.indexOf('good',24)); // 51
const quote = "every day may not be good... but there's something good in every day";
console.log(quote.lastIndexOf('good')); // 51
console.log(quote.lastIndexOf('good',24)); // 21
const word1 = 'feel';
const word2 = 'flee';
// returns -1
// because word1 comes before word2
console.log(word1.localeCompare(word2))
const fName = new String('Aya');
const lName = 'Bouchiha';
console.log(fName); // [String: 'Aya']
console.log(fName.valueOf()); // Aya
console.log(lName.valueOf()); // Bouchiha
const moroccanCity = new String('tanger');
console.log(moroccanCity); // [String: 'tanger']
console.log(moroccanCity.toString()) // tanger