Array Flashcards

0
Q

Array:

What method checks all the elements in an array and returns a new array of elements that pass a specific test?

A

Array.filter( )

var filtered  = [10,15,20].filter( function(n) { 
   return n > 10;
});

Returns a new array of elements for which n > 10 is true.

Not available in IE8.

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

Array:

What method invokes a specified function on each member of an array?

A

Array.map( )

var newArray = [1,4,9].map(Math.sqrt);

Creates a new array of the square roots of 1, 4, and 9.

This is not available in IE8.

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

Array:

Does JavaScript support multi dimensional arrays?

A

No

To approximate a multi dimensional array make an array of arrays.

var twoDim = new Array(5);
for(var i=0; i < twoDim.length; i++)
   twoDim[i] = new Array(5);
   twoDim[3][4] = "row 3 col 4";
How well did you know this?
1
Not at all
2
3
4
5
Perfectly