JS Course 1: Fundamental 4 Array Methods, method-like Loops and Properties Flashcards
What is the “length” property?
This property is an array property that returns the length of an array in numbers, aka how many items are in an array.
What is the Array.forEach() function and what does it do?
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.
What is the push() method and what does it do?
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.
What is the Array.isArray() method and what does it do?
This method can take an argument that will test if it is an array. It will return a boolean value.
What is the “instanceof” operator?
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.
What is the toString() method and what does it do?
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!
What is the join() method and what does it do?
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.
What is the pop() method and what does it do?
This method removes the last element from an array.
What is the shift() method and what does it do?
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.
What is the unshift() method and what does it do?
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.
What is the concat() method and what does it do?
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.
What is the flat() method and what does it do?
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.
What is the splice() method and what does it do?
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!
What is the slice() method and what does it do?
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.
What is the map() loop and what does it do?
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.