Array Obj properties and methods Flashcards
Review
what do the methods arr.push() and arr.unshift do? explain the syntax and parameters
They add things to the end or beginning of an array respectively
what do the methods arrVar.pop() and arrVar.shift() do? explain the syntax and parameters
used to remove elements to end or front of array.
What does the method arrVar.fill() do?explain the syntax and parameters
fill an array with a given value, can include a range
What does the method arrVar.reverse()? explain the syntax and parametersdo?
used to reverse the order of an array.
What does the method arrVar.sort() do? explain the syntax and parameters what is the default sort order?
used to sort arrays in place. insert (a,b)=>a-b for acc order. remember if it starts with a it’s accending.
How do we implement destructing, give an example with proper syntax
let [a, b, …rest] = [10, 20, 30, 40, 50];
console.log(rest); // expected output: [30,40,50]
What does the method arrVar.slice() do? Give an alternative way for the same effect, also what is the parameter syntax
use arr.slice() or […arrVar] used to copy an existing array.
Slice’s syntax is arr.slice(begin index for slice,endindex for slice(excluded);
We can use negative numbers in slice to start from the back of an array and just copy the last item arr.slice(-1) if ther eis only one parameter passed this will return from the passed index to the end of the array.
What does the method arrVar.indexof() of arrVar.lastIndexOf() do? What are the parameters taken.
used to return the first/last index of an value in an array or returns -1. takes a second option parameter for the index of where to start the search (included).
What does the method arrVar.includes() do?explain the syntax and parameters
used to check an array (or string) to see if ti includes a certain value. returns true or false.
What does the method arrVar.join() do?explain the syntax and parameters
used to join elements of an array… can also use arr.concat(arr2) or we can use the spread operator return […arr,…arr2] arrVar.toString() can be used to return it as well.
What does the method arrVar.splice() do? explain the syntax and parameters
Adds and/or removes element(s) from an array.
arr.splice(beginIndex,HowmanyToDelete,)
What are the properties of an array object? explain the syntax and what it does.
used to check the length of an array.
What does the method arrVar.every() do? explain the syntax and parameters
used to check every element in array against a statement, returns true if all pass, otherwise returns false.
arrVar.every((x)=>x>3)
What does the method arr.some() do? explain the syntax and parameters
used to potentially check every element in array against a statement, returns true if one passes, otherwise returns false.
arr.some((x)=>x>3)
What does the method arrVar.filter() do? explain the syntax and parameters
used to create a new array with all elements that pass the test. ex. all num above 10 & all str that pass /^\w/ regex.test.
arrVar.filter((x)=>x>3)