Part 3- A Smarter Way to Learn JavaScript Flashcards
What are the rules for naming an array?
array names have the same naming conventions as other variables
What types of data can an array hold?
Same as any other variable: strings, numbers, variables
Can you mix data types in the same array?
Yes.
Which punctuation is used in an array?
*the list of elements has square brackets: [],
*you separate elements in the list with a comma and a space
*in an array of strings, the comma between elements goes AFTER the quotation mark.
In an array, what’s another name for a value?
an element
How do you formally refer to a specific element in an array?
The array’s name
followed by the index number inside of straight brackets
For example, cities[5] would be how you refer to the sixth element in an array called CITIES
What’s the keyword to add elements to the end of an array?
*push()
*arrayname.push(elements);
*Think of it as “push parentheses”
What’s the keyword to remove the last element of an array?
pop();
arrayname.pop();
Think of it as “pop parentheses”
Do you have to add all elements to an array in order?
No.
What happens if you call an element and it hasn’t been assigned?
It will return “undefined.”
What are the six keywords used to change the elements in an array?
pop()
push()
shift()
unshift()
splice()
slice()
*Each of these methods RETURNS a value. When we get to the W3Schools tutorial, I’ll learn which value each returns
What do pop() and shift() have in common?
They both remove elements from an array
What do push() and unshift() have in common?
They both add elements to an array
What do pop() and push() have in common?
They both work at the end of an array
What do shift() and unshift() have in common?
They both work at the beginning of an array