JS methods Flashcards
Why do we log things to the console?
to double check work
What is a method?
method is a function within an object
property holding a function
How is a method different from any other function?
functions are called by name, methods are called by objects
How do you remove the last element from an array?
.pop( ) EXAMPLE var numbers = ['1', '2', '3'] console.log(numbers.pop( ) ); return '3' console.log(numbers); return ['1', '2']
How do you round a number down to the nearest integer?
Math.floor( ) EXAMPLE Math.floor(5.95) return 5 Math.floor(5.05) return 5
How do you generate a random number?
Math.random( );
How do you delete an element from an array?
.splice( ) EXAMPLE
var months = [‘jan’, ‘march’]
months.splice(1, 0, ‘feb’)
return [‘jan’, ‘feb’, ‘march’]
var months = ['jan', 'feb', 'April'] months.splice(2, 1, 'march') return ['jan', 'feb', 'march']
How do you append an element to an array?
objectName.push(element)
How do you break a string up into an array?
objectName.split( )
Do string methods change the original string? How would you check if you weren’t sure?
no, console.log(‘string’) or MDN
Roughly how many string methods are there according to the MDN Web docs?
MANY
Is the return value of a function or method useful in every situation?
no
Roughly how many array methods are there according to the MDN Web docs?
MANY
What three-letter acronym should you always include in your Google search about a JavaScript method or CSS property?
MDN