Arrays Flashcards Preview

JavaScript > Arrays > Flashcards

Flashcards in Arrays Deck (6)
Loading flashcards...
1
Q

Is array’s splice() method destructive to the array you call it on? I.e, if myArr is array and you call myArr.splice() will it modify myArr?

A

Yes it will.

2
Q

Is array object’s slice() method destructive to the array you call it on?

A

No

3
Q

How to check if an item exists in the array?

For example, if array is var myArr = ["ab", "cd", "ef"];
How can you check if value "cd" is in this array?
A

use indexOf() method of the array object.

var ind = myArr.indexOf(“cd”);

4
Q

Having an array: myArr = [“ab”, “cd”, “ef”];
and the following line:

var ind = myArr.indexOf(“gh”);

What would ind variable be set to?

A

-1

method indexOf() of array object returns the index of the item indicated by the parameter. If the item is not found in the array, indexOf() returns -1.

5
Q

Define the array “myArr” holding three numbers: 4,2 and 1

A

var myArr = [4,2,1];

6
Q

Define the array “myArr” holding two strings: “String1” and “String2”

A

var myArr = [“String1”, “String2”];