Arrays and Collections Flashcards
What is wrong with the code below?
var varName = ArrayList.of(2,4,6);
ArrayList should be Array
What is an array?
Objects that can hold mutliple values or objects
How can you create an array?
By setting a variable to a set of empty brackets (let values = []) Arrays can also be created using Array.of (i.e. let values = Array.of(1,2,3)
What are the items in an array called?
Elements
How can you access a value in an array?
By specifying the index number const values = [1, 2, 3] values[0] = 1
How can you add items to the end of an array?
push()
How can you remove a value from the end of array?
pop()
How do you remove a value from the beginning of an array?
shift()
How do you add a value to the beginning of an array?
unshift()
What does the slice method accomplish?
The slice() method returns a shallow copy of a portion of an array into a new array object selected from start to end (end not included) where start and end represent the index of items in that array. The original array will not be modified.
What method would you use to add items to the middle of an array (not beginning or end)?
array.splice()
Array.fill()
Changes all elements in an array to a static value from a start index (default is 0) to an end index (default is array.length). It returns a modified array.
What are data collections?
- Stores and structures large amounts of data types for easy access.
- Provides Methods to access that data.
What are data collection types in JavaScript ES6?
- Sets
- Maps
- WeakSets
- WeakMaps
What is a set?
unique values of any type (primitive or object references)