JavaScript Problems Flashcards
let arrOne = [“soccer”, “football”]
let arrTwo = [“basketball”, “baseball”]
let answer = arrOne.concat(arrTwo)
console.log(answer)
[“soccer”, “football”, “basketball”, “baseball”]
arr.push(…items)
Adds items to the end
arr.pop()
Extracts item from the end
arr.shift()
Extracts item from the beginning
arr.unshift(…items)
Adds items to the beginning
let arr = [“I”, “study”, “JavaScript”];
arr.splice(1, 1);
let arr = [“I”, “study”, “JavaScript”];
arr.splice(1, 1); // from index 1 remove 1 element
alert( arr ); // [“I”, “JavaScript”]
let arr = [“I”, “study”, “JavaScript”, “right”, “now”];
arr.splice(0, 3, “Let’s”, “dance”);
let arr = [“I”, “study”, “JavaScript”, “right”, “now”];
// remove 3 first elements and replace them with another
arr.splice(0, 3, “Let’s”, “dance”);
alert( arr ) // now [“Let’s”, “dance”, “right”, “now”]
let arr = [“I”, “study”, “JavaScript”];
arr.splice(2, 0, “complex”, “language”);
let arr = [“I”, “study”, “JavaScript”];
// from index 2
// delete 0
// then insert “complex” and “language”
arr.splice(2, 0, “complex”, “language”);
alert( arr ); // “I”, “study”, “complex”, “language”, “JavaScript”