Arrays Flashcards
(6 cards)
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?
Yes it will.
Is array object’s slice() method destructive to the array you call it on?
No
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?
use indexOf() method of the array object.
var ind = myArr.indexOf(“cd”);
Having an array: myArr = [“ab”, “cd”, “ef”];
and the following line:
var ind = myArr.indexOf(“gh”);
What would ind variable be set to?
-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.
Define the array “myArr” holding three numbers: 4,2 and 1
var myArr = [4,2,1];
Define the array “myArr” holding two strings: “String1” and “String2”
var myArr = [“String1”, “String2”];