Arrays - Reading Assignment

  1. Allows you to store a multiple of values in a single value. Its a collection of variables of the same type. e.g fruits (mango, apple,orange)

2.index 0 to access first element in an array.

1 Like
  1. Arrays allows us to hold multiple values in a defined variable.
  2. index 0
1 Like
  1. What do arrays allow us to do?
    Arrays are used to store multible values of same data type in a single variable.

  2. What index should you use in order to access the first element in an array?
    Index 0.

1 Like
  1. What do arrays allow us to do?
    Arrays allow us to group elements together bound to a single variable and perform a substantial variety of functions on them.

  2. What index should you use in order to access the first element in an array?
    [0]

1 Like

1 What do arrays allow us to do?

You can store multiple values into a variable.

2 What index should you use in order to access the first element in an array?

IndexOf([0])

1 Like
  1. Arrays allows us to store multiple values of the same type in one var.
  2. index 0
1 Like
  • What do arrays allow us to do?
    Store multiple values in a single variable.

  • What index should you use in order to access the first element in an array?
    zero

1 Like

An array lets us store several different variables in one variable name.

array[0] would be the first variable in the array.

1 Like
  1. Arrays are used to store a collection of variables of the same type.

  2. They do by default start at zero, the first element is in index 0.

1 Like
  1. What do arrays allow us to do?
    Arrays allow you to store multiple values in a single variable.

  2. What index should you use in order to access the first element in an array?
    indexOf()

1 Like

1: Arrays allow us to store multiple values in a single variable. An array is used to store a collection of data.

2: Arrays starts counting at 0 so to get the first element we write [0], the second element is [1] and so forth.

1 Like

Hi @keithra1948,

Q1 :ok_hand:

No…the first element in an array is at index 0, and so we access it as follows:

let array = [2, 4, 8, 16, 32];
console.log(array[0]);           // => 2

indexOf() is an array method which will return the index of the first element whose value matches the parameter. If no element exists with that value, then -1 is returned e.g.

let array = [2, 4, 8, 16, 32];
console.log(array.indexOf(2));           // =>  0
console.log(array.indexOf(8));           // =>  2
console.log(array.indexOf(7));           // => -1

I hope that makes things clearer for you :slightly_smiling_face:

Just let us know if you have any questions.

1 Like

1 - Arrays are variables capable of holding multiple values.
2- To access the first element you need to use 0.

1 Like
  1. What do arrays allow us to do?
    Arrays can store multiple values (elements of the same type) in a single variable.
  2. What index should you use in order to access the first element in an array?
    nameOfArray[0]
1 Like

1. What do arrays allow us to do?
They allow us to store multiple values in a single variable.

2. What index should you use in order to access the first element in an array?
Arrays start at 0.

1 Like
  1. What do arrays allow us to do?

It allows us to store multiple values in the same variable, we group them with these “[ ]” brackets, and place a comma next to each value to divide them. We can store any kind of values (strings, numbers and booleans) as long as they are of the same type. To simplify and array is a collection of data of the same type.

  1. What index should you use in order to access the first element in an array?

The index of the first element in every array is 0.

1 Like

Hi @Ernest_SG,

Nice answers :ok_hand:

In fact, an array can store values of different types, although you are right that they are predominantly used to store and manipulate values of the same type.

The key thing with arrays is that they store their values as a sequence: each element is an indexed value (an “index/value pair”).

1 Like

1. What do arrays allow us to do?

They allow us to list multiple elements into one variable, i.e. we can create a collection of elements and store them in one variable.

2. What index should you use in order to access the first element in an array?

0

1 Like
  1. What do arrays allow us to do?
    Arrays allow us to store multiple values, in sequential order, for a variable. For example,

var christmasList = gifts [“New Shed” , “G.I.Joe” , “Wacky Inflatable Arm Flailing Tube Man”]

  1. What index should you use in order to access the first element in an array?
    Instead of starting at 1, as conventional counting would have us do, we start at zero for arrays. It is also best practise, in most cases, to count from zero with programming anyway. It is easier to think of it not as at what number to start from but as how many numbers from the beginning do you want to start. For example, if I want the first value in the array, it is 0 positions away from the start and the second value is 1 position away from the beginning of the array values. The same concept can be used in a loop counter - the first number would be 0 positions away from the start of the count, therefore we use 0.
1 Like

1. What do arrays allow us to do?
Through the Array object it is possible to store multiple values in a single variable.

2. What index should you use in order to access the first element in an array?
index[0] - accesses the first element.

1 Like