Javascript Methods Flashcards
What is a method?
a function that is an object property
How is a method different from any other function?
methods are associated with an object; functions are not
How do you remove the last element from an array?
array.pop( );
How do you round a number down to the nearest integer?
Math.floor( );
How do you generate a random number?
Math.random( );
to figure out max 0 < 1 and does not include 1
How do you delete an element from an array?
array.splice(index, # of items to delete, [item1 to be added, item2 to be added, etc])
[optional part!]
kind of like selective surgery on an array
How do you append an element to an array?
array. push( new item1, new item2, etc. )
prepend: array.unshift ( );
How do you break a string up into an array?
string.split ( pattern/delimiter );
opposite is array.join ( pattern/delimiter );
Do string methods change the original string? How would you check if you weren’t sure?
No, strings are unchangeable
can console.log it
Roughly how many string methods are there according to the MDN Web docs?
~ 50
Is the return value of a function or method useful in every situation?
no, sometimes the return value is not needed, like in a push
Roughly how many array methods are there according to the MDN Web docs?
~ 50
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN
What is Array.prototype.reduce useful for?
take and array and condense content into a SINGLE VALUE
essentially can loop through an array and reduce to single value
What is Array.prototype.filter useful for?
creates new array with all elements that pass the test implemented by provided function
useful for accessing properties on objects