Mozilla "Array" Flashcards

1
Q

The ________ method creates a new, shallow-copied Array instance from an array-like or iterable object

A

Array.from()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
console.log((\_\_\_\_\_\_\_\_\_\_'foo'));
// expected output: Array ["f", "o", "o"]
console.log(\_\_\_\_\_\_\_\_\_\_\_([1, 2, 3], x => x * x));
// expected output: Array [2, 4, 6]
A

Array.from

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

The __________ method is used to merge two or more arrays. This method does not change the existing arrays, but instead returns a new array.

A

concat()

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q
var array1 = ['a', 'b', 'c'];
var array2 = ['d', 'e', 'f'];
console.log(array1.\_\_\_\_\_\_\_\_(array2));
// expected output: Array ["a", "b", "c", "d", "e", "f"]
A

concat

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q
var array1 = ['a', 'b', 'c'];
var array2 = ['d', 'e', 'f'];
console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_);
// expected output: Array ["a", "b", "c", "d", "e", "f"]
A

array1.concat(array2)

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

The_______method creates a new Array instance from a variable number of arguments, regardless of number or type of the arguments.

A

Array.of()

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

The ___________ method determines whether the passed value is an Array.

A

Array.isArray()

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

Array.of(7); //

A

[7]

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

Array(7) //

A

[ , , , , , , ]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
console.log(Array.\_\_\_\_\_([1, 2, 3], x => x + x));
// expected output: Array [2, 4, 6]
A

from

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

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.

A

join()

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

var elements = [‘Fire’, ‘Air’, ‘Water’];

console.log(elements.join());
// expected output: 
console.log(elements.join('-'));
// expected output:
A

“Fire,Air,Water”

“Fire-Air-Water”

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

var elements = [‘Fire’, ‘Air’, ‘Water’];

console.log(\_\_\_\_\_\_\_\_\_\_\_\_);
// expected output: "Fire-Air-Water"
A

elements.join(‘-‘)

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

The ________ method returns a new Array Iterator object that contains the keys for each index in the array.

A

keys()

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

The __________ method reverses an array in place. The first array element becomes the last, and the last array element becomes the first.

A

reverse()

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

The _______ method creates and returns a new string, the ______ method a array

A

join()

concat()

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

The ____________ method tests whether all elements in the array pass the test implemented by the provided function. It returns a Boolean value.

A

every()

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

The every() returns a _________

A

Boolean value.

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
19
Q
function isBelowThreshold(currentValue) {
  return currentValue < 40;
}

var array1 = [1, 30, 39, 29, 10, 13];

console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_);
// expected output: true
A

array1.every(isBelowThreshold)

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

Array.of(7); //

Array.of(1, 2, 3); //

A

[7]

[1, 2, 3]

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

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.

A

sort()

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

The _________ method returns a string representing the specified array and its elements.

A

toString()

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

var array1 = [1, 2, ‘a’, ‘1a’];

console.log(\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_\_);
// expected output: "1,2,a,1a"
A

array1. toString()

array1. join()

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

The __________ method determines whether an array includes a certain value among its entries, returning true or false as appropriate.

A

includes()

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

includes() returns _________?

A

true or false

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

2 ways of creating array

let arr =
let arr =

A
new Array();
[];
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
27
Q
let fruits = ["Apple", "Orange", "Plum"];
fruits[2] = 'Pear'; //
A

now [“Apple”, “Orange”, “Pear”]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
28
Q
let fruits = ["Apple", "Orange", "Plum"];
fruits[3] = 'Lemon';
A

// now [“Apple”, “Orange”, “Pear”, “Lemon”]

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

let fruits = [“Banana”]

let arr = fruits;

alert( arr === fruits ); //

A

true

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

let fruits = [“Apple”, “Orange”, “Plum”];

// iterates over array elements USING FOR OF

A

for (let fruit of fruits) {
alert( fruit );
}

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

let arr = [1, 2, 3, 4, 5];

arr.length = 2;
alert( arr ); // [1, 2]

arr.length = 5; // return length back
alert( arr[3] ); // ??

A

undefined: the values do not return

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

simplest way to clear the array is _______

A

arr.length = 0;

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

let arr = new Array(2)

alert( arr[0] ); //

A

undefined! no elements.

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

let arr = new Array(2); // will it create an array of [2] ?

alert( arr.length ); //

A

length 2

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

let arr = [“I”, “go”, “home”];

delete arr[1];

alert( arr[1] ); //

alert( arr.length ); //

A

undefined

3

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

The _________ method allows to run a function for every element of the array.

A

forEach

37
Q
arr.forEach(function(\_\_\_\_ , \_\_\_\_\_\_\_\_ , \_\_\_\_\_\_\_) {
  // ... do something with item
});
A

item, index, array

38
Q

3 search methods for array

A

indexOf,
lastIndexOf
includes

39
Q

let arr = [1, 0, false];

alert( arr.indexOf(0) ); //
alert( arr.indexOf(false) ); //
alert( arr.indexOf(null) ); //
alert( arr.includes(1) ); //

A

1

2

-1

true

40
Q

let result = arr.find(function(__ , ______ , ______) {

});

returns

A

item, index, array

41
Q
let users = [
  {id: 1, name: "John"},
  {id: 2, name: "Pete"},
  {id: 3, name: "Mary"}
];

let user = users.find(item => item.id == 2);

alert(user.name); //

A

Pete

42
Q
let users = [
  {id: 1, name: "John"},
  {id: 2, name: "Pete"},
  {id: 3, name: "Mary"}
];

let user = users.find(_____________);

alert(user.name); // John

A

item => item.id == 1

43
Q
var myA1 = [1,2,3];
var myA2 = [1,2,3];

console.log(myA1==myA2);

A

false

44
Q

let arr = [ 1, 2, 15 ];

// the method reorders the content of arr (and returns it)
arr.sort();

alert( arr ); //

A

1, 15, 2

45
Q

let arr = [ 1, 2, 15, 155 ];

arr.sort();

alert( arr );

A

1, 15, 155, 2

46
Q

“2” > “15”

A

TRUE

47
Q
function compareNumeric(a, b) {
  if (a > b) return 
  if (a == b) return 
  if (a < b) return 
}
A

1

0

-1

48
Q

let str = “test”;

alert(________); // t,e,s,t

A

str.split(‘’)

49
Q

When we need to iterate over an array – we can use _____________________ name all 3

A

forEach, for or for..of.

50
Q

The ____________ method executes a provided function once for each array element.

A

forEach()

51
Q

_________— executes a provided function once for each array element.
__________— creates a new array with the results of calling a provided function on every element in the calling array.

A

forEach() 

map() 

52
Q

The ________method shallow copies part of an array to another location in the same array and returns it without modifying its length.

A

copyWithin()

53
Q

copyWithin()

A

The copyWithin() method shallow copies part of an array to another location in the same array and returns it without modifying its length.

arr.copyWithin(target[, start[, end]])

54
Q

var array1 = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’];

console.log(array1.copyWithin(0, 3, 4));
// expected output:
A

Array [“d”, “b”, “c”, “d”, “e”]

55
Q

var array1 = [‘a’, ‘b’, ‘c’, ‘d’, ‘e’];

console.log(array1.copyWithin(1, 3));
// expected output:
A

Array [“d”, “d”, “e”, “d”, “e”]

56
Q

arr.copyWithin(________)

A

target[, start[, end]]

57
Q

The ___________ method returns the first index at which a given element can be found in the array, or -1 if it is not present.

A

indexOf()

58
Q

var beasts = [‘ant’, ‘bison’, ‘camel’, ‘duck’, ‘bison’];

console.log(beasts.indexOf('bison'));
// expected output:
A

1

59
Q

var beasts = [‘ant’, ‘bison’, ‘camel’, ‘duck’, ‘bison’];

// start from index 2
console.log(beasts.indexOf('bison', 2));
// expected output:
A

4

60
Q

var beasts = [‘ant’, ‘bison’, ‘camel’, ‘duck’, ‘bison’];

console.log(beasts.indexOf('giraffe'));
// expected output:
A

// expected output: -1

61
Q

arr.indexOf(_________[,__________])

A

searchElement

fromIndex

62
Q

var array1 = [1, 2, 3];

console.log(array1);
// expected output:
A

Array [1, 2, 3]

63
Q

arr.copyWithin(______[,________[, ______]])

A

target . start . end

64
Q

USE .some or .every?

const userPrivileges = ['user', 'user', 'user', 'admin'];
const containsAdmin = userPrivileges.\_\_\_\_\_\_\_( element => element === 'admin');
// containsAdmin will be equal to true
A

some

65
Q

use .some or .every?

const ratings = [3, 5, 4, 3, 5];
const goodOverallRating = ratings.\_\_\_\_\_\_( rating => rating >= 3 );
// goodOverallRating will be equal to true
A

every

66
Q
const icecreamColors = {
    chocolate: 'brown',
    vanilla: 'white',
    strawberry: 'red',
}
const colors =\_\_\_\_\_\_\_\_\_\_;
// colors will be equal to ["brown", "white", "red"]
A

Object.values(icecreamColors)

67
Q
const icecreamColors = {
  chocolate: 'brown',
  vanilla: 'white',
  strawberry: 'red',
}
const types = \_\_\_\_\_\_\_\_\_
// types will be equal to ["chocolate", "vanilla", "strawberry"]
A

Object.keys(icecreamColors);

68
Q
var arr = [[1,2], [3,4], [5,6]];
alert the number 5
A

alert(arr[2][0]);

69
Q

The _________ method tests whether at least one element in the array passes the test implemented by the provided function. It returns a Boolean value.

A

some()

70
Q

The _________ method returns the last index at which a given element can be found in the array, or -1 if it is not present. The array is searched backwards, starting at fromIndex.

A

lastIndexOf()

71
Q
var animals = ['Dodo', 'Tiger', 'Penguin'];
console.log(animals.lastIndexOf('Penguin'));
// expected output: 
console.log(animals.lastIndexOf('Dodo'));
// expected output:
A

2

0

72
Q

The___________ method fills (modifies) all the elements of an array from a start index (default zero) to an end index (default array length) with a static value. It returns the modified array.

A

fill()

73
Q

var array1 = [1, 2, 3, 4];

array1.fill(6) returns

A

// expected output: [6, 6, 6, 6]

74
Q

var array1 = [1, 2, 3, 4];

console.log(array1.fill(0, 2, 4));

A

// expected output: [1, 2, 0, 0]

// fill with 0 from position 2 until position 4

75
Q
var array1 = [1, 2, 3, 4];
console.log(array1.fill(5, 1));
A

// expected output: [1, 5, 5, 5]

76
Q

var array = [2, 9, 9];

array.indexOf(7); //

A

-1

77
Q

var array = [2, 9, 9];

array.indexOf(9, 2); //

A

2

78
Q
var array = [2, 9, 9];
array.indexOf(2, -1); //
A

-1

79
Q
var array = [2, 9, 9];
array.indexOf(2, -3); //
A

0

80
Q

__________syntax allows an iterable such as an array expression or string to be expanded in places where zero or more arguments (for function calls) or elements (for array literals) are expected, or an object expression to be expanded in places where zero or more key-value pairs (for object literals) are expected.

A

Spread operator

81
Q
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum(...numbers));
// expected output:
A

6

82
Q
function sum(x, y, z) {
  return x + y + z;
}

const numbers = [1, 2, 3];

console.log(sum.apply(null, numbers));
// expected output:
A

6

83
Q

Concating these two arrays will result//

my arr1 = [[“steve”, 33],[“me”, 22]]
my arr2 = [“john”, 55]

A

[[“steve”, 33],[“me”, 22], “john”, 55]

84
Q

Concating these two arrays will result//

my arr1 = [[“steve”, 33],[“me”, 22]]
my arr2 = [[“john”, 55]]

A

[[“steve”, 33],[“me”, 22], [“john”, 55]]

85
Q

let array1 = [1,2,3];
let array2 = [4,5,6];
let array3 = // concat using … spread syntax

A

[…array1,…array2];

86
Q

let array1 = [1,2,3];
let array2 = [4,5,6];
let array3 = // concat using concat()

A

console.log(array1.concat(array2));

87
Q
var blue = {
color:blue;
}

let colors = [{color:red}, {color:blue}];

var index = indexOf(blue) // returns

A

-1

referencing the blue object

88
Q
var blue = {
color:blue;
}

let colors = [{color:red}, blue];

var index = indexOf(blue) // returns

A

1

referencing from array

89
Q

arr.indexOf(_________)

A

searchElement[, fromIndex]