Methods Flashcards
Imports a library as an object
node require(library)
ie let obj = require(‘readline-sync’)
destructive, pushes a new element to the end of an array.
Array.push()
non-destructive, returns a brand new array that contains all the elements from the original array followed by all of the arguments passed to it:
Array.concat()
destructive, changes the contents of an array by removing or replacing existing elements and/or adding new elementsin place
Array.splice(start, deleteCount)
non-destructive, creates a new array populated with the results of calling a provided function on every element in the calling array.
Array.map()
non-destructive, returns a new array that includes all elements from the calling array for which the callback returns a truthy value.
Array.filter()
non-destructive, reduces the contents of an array to a single value.
Array.reduce()
reducetakes two arguments: a callback function and a value that initializes something called theaccumulator.
non-destructive
determines whether an array includes a given element
Array.includes()
non-destructive, searches an array for an element with a given value and returns the index of the found element. If the element is not found,returns-1.
Array.indexOf()
destructive, rearranges the elements of an array in sequence. It returns a sorted array.
Array.sort()
non-destructive, extracts and returns a copied portion of the array. It takes two optional arguments. The first is the index at which extraction begins, while the second is where extraction ends (non inclusive of the last index)
Array.slice()
destructive, reverses the order of an array.
Array.reverse()
This static method returns an object’s keys as an array. You can iterate over that array using any technique that works for arrays.
Object.keys()
returns the object’s own keys: it does not include any keys from the prototype objects.
This static method extracts the values from every own property in an object to an array:
Object.values()
This static method returns an array of nested arrays. Each nested array has two elements: one of the object’s keys and its corresponding value:
Object.entries()
merges two or more objects to a single object by mutating the first object. Returns the new object.
Object.assign(objA, objB)
can be used with an empty object in first place if you want to simply make a copy and not modify the first object.
This method checks if some elements exists in an array, and returnstrueorfalse. This is somewhat similar to the concept of theincludes()method, except the argument is a function and not a string.
.some()
method loops through the array, checks every item, and returnstrueorfalse. Same concept assome(). Except every item must satisfy the conditional statement, otherwise, it will returnfalse.
.every()
This method is responsible for changing all elements on the array to a static value, starting from the first index (set as 0) to the last index. During this process, updates will finish and return a reference array to the original.
.fill()