Mozilla "Array" Flashcards
The ________ method creates a new, shallow-copied Array instance from an array-like or iterable object
Array.from()
console.log((\_\_\_\_\_\_\_\_\_\_'foo')); // expected output: Array ["f", "o", "o"]
console.log(\_\_\_\_\_\_\_\_\_\_\_([1, 2, 3], x => x * x)); // expected output: Array [2, 4, 6]
Array.from
The __________ method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.
concat()
var array1 = ['a', 'b', 'c']; var array2 = ['d', 'e', 'f'];
console.log(array1.\_\_\_\_\_\_\_\_(array2)); // expected output: Array ["a", "b", "c", "d", "e", "f"]
concat
var array1 = ['a', 'b', 'c']; var array2 = ['d', 'e', 'f'];
console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_); // expected output: Array ["a", "b", "c", "d", "e", "f"]
array1.concat(array2)
The_______method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments.
Array.of()
The ___________ method determines whether the passed value is an Array.
Array.isArray()
Array.of(7); //
[7]
Array(7) //
[ , , , , , , ]
console.log(Array.\_\_\_\_\_([1, 2, 3], x => x + x)); // expected output: Array [2, 4, 6]
from
The _________ method creates and returns a new string by concatenating all of the elements in an array (or an array-like object), separated by commas or a specified separator string. If the array has only one item, then that item will be returned without using the separator.
join()
var elements = [‘Fire’, ‘Air’, ‘Water’];
console.log(elements.join()); // expected output:
console.log(elements.join('-')); // expected output:
“Fire,Air,Water”
“Fire-Air-Water”
var elements = [‘Fire’, ‘Air’, ‘Water’];
console.log(\_\_\_\_\_\_\_\_\_\_\_\_); // expected output: "Fire-Air-Water"
elements.join(‘-‘)
The ________ method returns a new Array Iterator object that contains the keys for each index in the array.
keys()
The __________ method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.
reverse()
The _______ method creates and returns a new string, the ______ method a array
join()
concat()
The ____________ method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.
every()
The every() returns a _________
Boolean value.
function isBelowThreshold(currentValue) { return currentValue < 40; }
var array1 = [1, 30, 39, 29, 10, 13];
console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_); // expected output: true
array1.every(isBelowThreshold)
Array.of(7); //
Array.of(1, 2, 3); //
[7]
[1, 2, 3]
The ________ method sorts the elements of an array in place and returns the sorted array. The default sort order is built upon converting the elements into strings, then comparing their sequences of UTF-16 code units values.
sort()
The _________ method returns a string representing the specified array and its elements.
toString()
var array1 = [1, 2, ‘a’, ‘1a’];
console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_); // expected output: "1,2,a,1a"
array1. toString()
array1. join()
The __________ method determines whether an array includes a certain value among its entries, returning true or false as appropriate.
includes()
includes() returns _________?
true or false
2 ways of creating array
let arr =
let arr =
new Array(); [];
let fruits = ["Apple", "Orange", "Plum"]; fruits[2] = 'Pear'; //
now [“Apple”, “Orange”, “Pear”]
let fruits = ["Apple", "Orange", "Plum"]; fruits[3] = 'Lemon';
// now [“Apple”, “Orange”, “Pear”, “Lemon”]
let fruits = [“Banana”]
let arr = fruits;
alert( arr === fruits ); //
true
let fruits = [“Apple”, “Orange”, “Plum”];
// iterates over array elements USING FOR OF
for (let fruit of fruits) {
alert( fruit );
}
let arr = [1, 2, 3, 4, 5];
arr.length = 2;
alert( arr ); // [1, 2]
arr.length = 5; // return length back
alert( arr[3] ); // ??
undefined: the values do not return
simplest way to clear the array is _______
arr.length = 0;
let arr = new Array(2)
alert( arr[0] ); //
undefined! no elements.
let arr = new Array(2); // will it create an array of [2] ?
alert( arr.length ); //
length 2
let arr = [“I”, “go”, “home”];
delete arr[1];
alert( arr[1] ); //
alert( arr.length ); //
undefined
3