String Flashcards
Change to uppercase:
.toUpperCase()
Change to lowercase:
.toLowerCase()
Remove leading & trailing whitespace from a string:
.trim()
Joins two or more strings:
.concat()
(ex.)let text1 = ‘Hello’;
let text2 = ‘World’;
let text3 = text1.concat(‘ ‘, text2);
console.log(text3);
»>’Hello World’
Replace string:
.replace()
Syntax: .replace(findValue, replaceValue)
Add a new item to the end
.push()
userName.push(“Aleesha”)
»>[“George”, “Alice”, “Rashid”, “Aleesha”]
Remove the last element of the array
.pop()
Remove the first element of the array
.shift()
Add new element at the beginning
.unshift()
By adding, removing, and inserting elements
.splice()
.splice(index, howMany, item1…, itemX);
let fruits =[“Banana”, “Orange”, “Apple”]
fruits.splice(2, 0, “Lemon”, “Kiwi”)
console.log(fruits)
> > > [“Banana”, “Orange”, “Lemon”, “Kiwi”, “Apple”]
Copies a given part of an array and returns that copied part as a new array
.slice()
array.slice(start, end)
Find a particular value in an array
.indexOf(searchValue, start)
Advanced array:
Reverse the order of the elements in an array
.reverse()
Advanced array:
Sort array in alphabetic order
.sort()