JS Course 1: Fundamental 4 Array Methods, method-like Loops and Properties Flashcards

1
Q

What is the “length” property?

A

This property is an array property that returns the length of an array in numbers, aka how many items are in an array.

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

What is the Array.forEach() function and what does it do?

A

This function sifts through every element in an array to finish a task. This function can take on an argument that is another function that will be applied to every item in the array.

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

What is the push() method and what does it do?

A

This method is the easiest way to add a new element to an array. It adds an element to the end of the array you’re editing. This method adds a new element to the end of an array.

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

What is the Array.isArray() method and what does it do?

A

This method can take an argument that will test if it is an array. It will return a boolean value.

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

What is the “instanceof” operator?

A

This operator returns true if an object is created by a given constructor.

Example:
array_name instanceof Array;

returns True because it is an array.

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

What is the toString() method and what does it do?

A

This method converts an array to a string of comma separated array values. JavaScript automatically converts an array to a comma separated string when a primitive value is expected. In other words, all JavaScript objects have a built-in toString() method!

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

What is the join() method and what does it do?

A

This method joins all array elements into a string, but the argument it takes on is quotes with whatever that’s inside the quotes to be the separator between the newly joined array elements.
Similar to “toString()” except the custom separator.

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

What is the pop() method and what does it do?

A

This method removes the last element from an array.

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

What is the shift() method and what does it do?

A

This method removes the first array element and shifts all other elements down one index number. This method also returns the value shifted out of the array.

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

What is the unshift() method and what does it do?

A

This method adds a new element to the beginning of an array and moves the other array elements up one index number. This method also returns the new array length.

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

What is the concat() method and what does it do?

A

This method creates a new array by merging existing arrays. It can take on several arguments (before the array array.concat() and inside the parentheses concat(arr1, arr2…).) The more left the argument is around the method, the more left it will be in the new array.

This method doesn’t change the source arrays and it can take strings as arguments following the same order left to right.

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

What is the flat() method and what does it do?

A

This method creates a new array with sub-array elements concatenated to a specified depth. basically, if there’s depth in an array with different levels of elements inside elements, this method will take all of the elements and put them onto the same level like a normal array with equal depth.

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

What is the splice() method and what does it do?

A

This method does multiple things!

This method primarily adds new items to an array in a specified place. This method can take on two initial parameters, the first one is the position where new elements are to be added, the second is how many element should be removed from the array. The items you then wish to add will be the parameters after the first two.

The second parameter can be left empty if you don’t want to remove any elements. You can even exclude items to include and just have the two initial parameters to just delete parts!

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

What is the slice() method and what does it do?

A

This method slices out a piece of an array into a new array (it returns the value of the sliced items.) It can take on one parameter (that defines the index position of a single element) or two parameters (to define a section of the array to slice into the new array.)

This method returns the value of the items you’ve sliced and this method does not remove elements from the source array.

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

What is the map() loop and what does it do?

A

This is a specialized loop made for collections/arrays. It can be used to do something to each item in a collection and create a new collection containing the changed items. What happens to each item is determined by argument in the parentheses which can be a function.

This loop is often written in function expression.

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

What is the filter() loop and what does it do?

A

This is a specialized loop made for collections/arrays. It can be used to test each item in a collection and create a new collection containing only items that match a condition. This loop is similar to map() but the function we call for each item in the array instead returns a boolean value to verify that each item passes a test.

This loop is often written in function expression.