JS Methods Flashcards
array.splice(startIndex, howMany)
Removes item(s) from an array and returns them.
array.slice(startIndex, endIndex)
Returns selected items as new array without modifying the original. params(startIndex, endIndex). Ending index is not inclusive. Works on string as well.
array.toString()
Turns array into a string, separated by commas
array.join(separator)
Turns array into string. Accepts a separator, determining how to separate each item in the array.
array.pop()
Removes and returns the last item in array.
array.push(newItem)
Adds a new item to the end of an array. Returns the new array length (integer).
array.shift()
Removes and returns first element in an array.
array.unshift(newItem)
Adds newItem to the beginning of an array. Returns the new array length (integer).
array.concat(secondArr)
Returns new array, the combination of the two arrays.
array.sort()
Sorts array alphabetically (lexicographically).
array.reverse()
Reverses the order of an array in place (modifies the original array).
array.sort(callbackFn)
Sorts the array in place as directed by the callback function
Math.max(num1, num2, num3, etc.)
Return largest number of the arguments provided
Math.min(num1, num2, num3, etc.)
Return smallest number of the arguments provided
Boolean(x > y)
Find if an expression is true or false.
string.length OR array.length
Returns length of string or array.
string.indexOf(‘something’)
Returns the index position of ‘something’ or else -1.
string.substr(x,y)
Returns a string beginning at x and length of y.
string.replace(x,y)
Replace x with y in the string.
string.substring(x,y)
Returns the string starting at index x up to but not including index y.