Week 3 Review Flashcards
Review Week 3 Readings and FCC
Loop over an array using “for”.
for (let i = 0; i < myArray.length; i++) { // Use myArray[i] to access each array element one by one }
Loop over an array using for each
myArray.forEach(myElement => { // Use myElement to access each array element one by one });
Loop through an array using for-of
for (const myElement of myArray) { // Use myElement to access each array element one by one }
Remove the 2nd, 3rd, and 4th element using splice
myArray.splice(1,3)
Splice syntax
Splice method with index of first element and second parameter is how many elements to remove
TF Strings are objects with methods and properties
True
TF A javascript string is immutable
True
Convert a string to lower case
myString.toLowerCase()
Convert a string to upper case
myString.toUpperCase
TF You can use == to compare two strings
False use ===
Access each letter of a string
for (let i = 0; i < myString.length; i++) { Console.log(myString[1]); }
Access each letter of a string using for of
const name = "Sarah"; for (const letter of name) { console.log(letter); }
Turn a string into an array
const name = "Sarah"; const nameArray = Array.from(name);
What does
const song = “Honky Tonk Women”;
console.log(song.indexOf(“Onk”));
Return
-1 because string not found because case mismatch
Break a string apart into array
myString = ’Jan, 12’
myString.split(“,“)