Arrays and Objects Flashcards

1
Q
What data type is the following:
let colors = ['blue', 'green', 'purple']
A

Array

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q
What data type is the following:
let colors = {'blue', 'green', 'purple'}
A

Object

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q
What will be console logged?
let dogs = ['Husky', 'Shiba Inu', 'Beagle', 'Dalmatian']
console.log( dogs[1] )
A

Shiba Inu

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

What index number do arrays start at?

A

0

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

Which array method will append something to the end of an array?

A

.push( )

Example Usage: 
let dogs = ['Husky', 'Shiba Inu', 'Beagle', 'Dalmatian'];
dogs.push('Golden Retriever');
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

Which array method can be used to cut something out of an array and add something else?

A

.splice( )

Example Usage:
let dogs = ['Husky', 'Shiba Inu', 'Beagle', 'Dalmatian']
dogs.splice(0, 1, 'Corgi')
//This will remove Husky and replace it with Corgi
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

The array method .splice( ) takes in three parameters. What is the purpose of each of these three parameters?

A

Array.splice(position, how many to cut, what to add in that location)

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
8
Q

What array method can be used to remove the last element of an array?

A

.pop( )

Example Usage:
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
characters.pop( )
//This will remove Peach
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
9
Q

What array method can be used to remove the first item of an array?

A

. shift( )

Example Usage: 
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
characters.shift( )
//This will remove Mario
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
10
Q
What will happen in the following code:
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
characters.unshift('Bowser', 'Wario')
A

It will add Bowser and Wario to the beginning of the array

[‘Bowser’, ‘Wario’, ‘Mario’, ‘Luigi’, ‘Yoshi’, ‘Peach’]

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
11
Q

What are the three arguments for a forEach( )

A
  1. ) currentValue = the current element being processed in the array
  2. ) index = the index of the current element being processed
  3. ) array = the array the forEach method was called upon
How well did you know this?
1
Not at all
2
3
4
5
Perfectly
12
Q
What is the syntax for a forEach( ) that will console log each of the items in this array?
let characters = ['Mario', 'Luigi', 'Yoshi', 'Peach']
A

characters.forEach(c => { console.log(c); })

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
13
Q

What will this console log?
let food = [‘Pizza’, ‘Pasta’, ‘Hamburger’, ‘Chips’, ‘Ice Cream’]
console.log(food.length)

A

5

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
14
Q

How would you step through this object and console log ‘fire’?

let pokemon = {
name: 'Bulbasaur',
id: 1,
type: ['grass', 'poison'],
weakness: ['psychic', 'flying', 'fire', 'ice'],
evolvesTo: 'Ivysaur',
description: 'A strange seed was planted on its back at birth. The plant sprouts and grows with this Pokémon.' 
}
A

console.log(pokemon.weakness[2])

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
15
Q

What does JSON stand for?

A

JavaScript Object Notation

How well did you know this?
1
Not at all
2
3
4
5
Perfectly