Arrays Flashcards

1
Q

What is an array?

A

Array ares a data structure.

Way store and organize data

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

Why are arrays better than variables?

A

Variables store strings, numbers, and booleans.

Variables can store single value only– which is limiting.

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

What types of data can arrays hold?

A

Strings

Numbers

Booleans

Even Other Arrays

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

What are 2 practical examples where arrays can be used?

A

Shopping list

Online order list

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

What’s the syntax of an array?

A

variable name = [];

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

What symbol do you use to separate list values?

A

commas

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

Does the last value in the list of array items have a comma?

A

No

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

Why should you breakup items?

A

Easier to read

Easier to edit

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

What is zero index?

A

The counting starts at 0.

Rather than at 1

First item is at 0 index.

Second item is at 1 index.

Third item is at 2 index.

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

What symbol do you use to return values?

A

[]

brackets

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

What happens if you list an item not on the list?

Example [4]

A

Last item is undefined in console because nothing in index 4.

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

script.js contains an array of string values (the names of players in a game). Practice using array indices by accessing individual names in the players array. Start by logging the first name inside the array using the console.log() method.

First Response:

const players = [‘Toni’, ‘Anwar’, ‘Mali’, ‘Carlos’, ‘Cormac’, ‘Sariah’];

A

Notice the syntax:

Parenthesis

variable name

Brackets

;

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

Complete the code below to log the message “Arrays are awesome” to the console:

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

Arrays are zero-based. What does that mean?

A

The index of the first element inside an array is 0 (not 1).

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

Which of the following best describes an array?

A

A collection of values you can assign to a single variable.

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

In this array, which code snippet prints the number 1 to the JS console?

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

What’s a great resource for JS?

A

MDN

Mozilla Developer Network

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

What does the length property do?

A

returns values in array

number of items in array

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

How do you add elements?

A

Use .push to add to the end of the array.

Use .unshift to the beginning of the array

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

What does .push do?

A

Adds elements

Adds to the end of an array

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

What does .unshift do?

A

.unshift adds an element to the beginning of an array

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

The array assigned to the guestList variable holds a list of names. Add two new names to the end of the array using the push() method. Make sure not to type the names directly inside the guestList array 😁.

A

variableName.push(‘Name1’, ‘Name2’);

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

Now add two names to the beginning of the array using the .unshift array method

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

How do you remove elements from an array?

A

.pop and .shift methods remove items from an array

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

How does the .pop method remove items?

A

.pop takes off the last item from the array

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

How does the .shift method remove elements?

A

Takes first item off from an array

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

How do you remove tuna from the list?

A

let [new variable name] = [variableWithList].shift();

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

What methods help create first in, first out?

A

.Push and .shift method work together:

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

What happens if you write numbers.length given this array?

A

It returns the length of 5

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

What happens if you apply numbers.push(600)?

A

Adds 600 to the const numbers array

.push adds to the end of an array

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

What happens if you apply numbers.unshift(0)?

A

You add 0 to beginning of an array

32
Q

What happens if you apply numbers.shift()

A

Returns 0

33
Q

The array assigned to the variable orderQueue
contains a list of order numbers.

Declare a new variable named shipping.

Remove the first element from the
orderQueue array and assign it to the shipping. variable.

A
34
Q

Next, declare a new variable named cancelled. Remove the last item from the orderQueue array and assign it to the variable cancelled. Use the array that method removes the last element from an array and returns it.

A

.pop()

returns last value

removes last value

35
Q

What is the spread operator look like?

A

3 dots + variable name

36
Q

What does the spread operator do?

A

The spread operator (…) a JS syntax that builds,
combines, and manipulate arrays quickly and seamlessly.

37
Q

How do you connect HTML and JS file?

A

Add a JS script tag to the index.html

38
Q

What is a two-dimensional array?

A

It’s an array within an array.

39
Q

How do you connect arrays with the spread operator?

A

You use the 3 dots and variable name

Example …middle

40
Q

How do you bring together two arrays into a new variable altogether?

A

Use spread operators … with variable names

41
Q

How would you remove an array?

A

Use woodwind.pop()

It would only remove from woodwind array

42
Q

How do you add items to the array to the front?

A

variableNames.unshift(‘item’, ‘itemB’)

43
Q

How would you extract the max number in a list of numbers using the spread operator?

const numbers = [10, 20, 30, 40];

A

See the console.log

44
Q

What does Math.max do?

A

Produces the highest number in a list within an array

45
Q

What does Math.min do?

A

It selects the lowest number within an array.

46
Q

Can you use the .push() method to add more than one element to an array at the same time? Is the following example, valid?

scores.push( 77, 76, 89);

A

Yes.

You can use push() to add any number of

elements to the end of an array.

47
Q

Please fill in the correct answer.

Complete the code by using the property that returns the number of elements in the attendees array.

A

attendees.length

48
Q

Which array method adds an element to the end of an array?

A

.push()

49
Q

Which of the following places the contents of

one array into another array?

A

The spread operator (…)

50
Q

Which array method returns the first element of an array and removes it from the array?

A

.shift() removes first item from beginning of the array

51
Q

Complete the code below to add the value of

23 the beginning of the ages array.

A

ages.unshift(23);

52
Q

What is the zero index values for

the following array of students?

A

Order/Name

0 Lee

1 Jan

2 Mali

3 Sarah

53
Q

What happens when the loop counter reaches 4?

A

When it reaches 4, it breaks the loop as

the array doesn’t have a 4th item.

54
Q

Why would you use a variable length counter?

A

students.length is superior coding because it

adjusts to changes in the array better

If student number changes, up/down,

program is flexible enough to run.

55
Q

What function would you use to create items in a list?

A

function is

createListItems

56
Q

What is arr?

A

Parameter

57
Q

What does the ${arr[i]}?

A

It returns values that matches i variable

58
Q

What’s the role of return items;?

A

it’s key to calling function

59
Q

What does the document.querySelector

section of code produce?

A

It puts all the songs in an ordered playlist

60
Q

What symbol do you use to keep conditions separate?

A

use the semi-colon ; to separate conditions

61
Q

Do you need a symbol after the closing curly brace }?

A

No, you don’t need a ; after a } curly brace.

62
Q

What does the the .join array method do?

A

.join() method creates and returns a new string by concatenating all of the elements in an array, separated by commas or specified separator string.

Joins list items in a variable by giving it a format consisting with spaces, dashes, or punctuation

63
Q

What does the array method .includes() do?

A

determines whether or not an item is found within an array by providing an answer as True or False for Yes and No respectively

true or false

true: found
false: not found

64
Q

If an item is found within an array, what response does the .includes() array method provide?

A

True

65
Q

What happens if you use the array method .includes() for an item that’s not found within an array, what response is provided in the JavaScript console?

A

False

Not found in the array

66
Q

Is the .includes() array method case sensitive?

A

Yes

It’s case sensitive.

The wrong case creates an error

Stick to lowercase

67
Q

What does .indexOf array method do?

A

Checks if value is found within an array

68
Q

Using the .indexOf array method

how does it use the zero index method?

A

-1 not found

if it is found in the array

69
Q

What does a positive number mean in the context of the .indexOf array method mean?

A

Positive numbers means the item is

found in the list of array items

70
Q

What does a negative number mean in the context of .indexOf()?

A

Negative number = not in the list of array items

71
Q

Use the array method that combines all of the elements inside the planets array into a single string. The final string should separate the array elements by a comma and space. Log the final string value to the console.

A

Logs the final string value to the console with the .join array method giving it a comma and space to bring the list items together with correct formatting

72
Q

Next, use the method that returns the position of ‘Saturn’ in the planets array. Log the return value to the console.

A

console.log(variableName.indexOf(‘Saturn’));

73
Q

How do you write an if/else statement to search an array based on a search? Just the if/else section

A

if (variableName.includes(search) {

message= Yes, we have ${search};

} else {

message = Sorry, we don't have ${search};

74
Q

How do you explain the logic behind this program?

A

FIrst, establish a variable assigned to an array with the list of items.

Second, create a variable that asks a prompt question

Create a third variable for the reply to the question

Fourth, create an if/else statement that searches the first variable using the second variable question to then produce yes/no messages if item is or isnt in stock

75
Q

What array method would you use to search the grocery list items to see if it is in stock?

A

.indexOf

array method

76
Q
A