JavaScript Problems Flashcards

1
Q

let arrOne = [“soccer”, “football”]
let arrTwo = [“basketball”, “baseball”]
let answer = arrOne.concat(arrTwo)
console.log(answer)

A

[“soccer”, “football”, “basketball”, “baseball”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

arr.push(…items)

A

Adds items to the end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

arr.pop()

A

Extracts item from the end

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

arr.shift()

A

Extracts item from the beginning

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

arr.unshift(…items)

A

Adds items to the beginning

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

let arr = [“I”, “study”, “JavaScript”];

arr.splice(1, 1);

A

let arr = [“I”, “study”, “JavaScript”];

arr.splice(1, 1); // from index 1 remove 1 element

alert( arr ); // [“I”, “JavaScript”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

let arr = [“I”, “study”, “JavaScript”, “right”, “now”];

arr.splice(0, 3, “Let’s”, “dance”);

A

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”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

let arr = [“I”, “study”, “JavaScript”];

arr.splice(2, 0, “complex”, “language”);

A

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”

How well did you know this?
1
Not at all
2
3
4
5
Perfectly