Arrays are fundamental concept in JavaScript that you gonna use throughout your entire Javascript life.

In previous lectures, we have assigned different variables for random data and people's input, imagine how enviable it would be to bundle them into one single variable, Luckily for us, In JavaScript, we have array to cater for that; they are collection of variables that can even have different data types.

Enough of the prologue, what really are Arrays??

According to MDN,

Arrays are list-like objects whose prototype has methods to perform traversal and mutation operations. Neither the length of a JavaScript array nor the types of its elements are fixed. Since an array's length can change at any time, and data can be stored at non-contiguous locations in the array, JavaScript arrays are not guaranteed to be dense; this depends on how the programmer chooses to use them. In general, these are convenient characteristics; but if these features are not desirable for your particular use, you might consider using typed arrays.

To be more explicit,

Array is a single variable that is used to store different elements. It is often used when we want to store list of elements and access them by a single variable. Unlike most languages where array is a reference to the multiple variable, in JavaScript array is a single variable that stores multiple elements.

Now that we are acquainted with what Arrays are, How then can we declare/ initialize an Array???

There are basically two ways to declare an array, see snippets below to learn more

//type 1 
     ↗️//variable name
var names = ['Ozil' , 'Fabregas','Sanchez'];
              ↘️// Array[]
//type 2

               ↗️/*new Array initialized
                   with the new Array()KW
                  */
var years = new Array(2013, 2006,2015);
    ↘️//var name

Notes from the above array illustration.

📍Arrays are of two types and are best assigned to a variable,

📍Arrays are housed by square braces[ ]/ normal parentheses ( ) i.e square braces for the first type of declaration and parentheses for the second type as illustrated above.

📍Array entries are separated by commas and entered with data types convention (i.e strings should be written as one and etc)

📍 NB: KW (keyword). Arrays housed by square braces should be given higher preference as it follows best practices.

Now that we've exemplified array as a 'database' 😂😄 so , how can we access elements(data/entries) in an array??

/*Let us retrieve the data stored above
remember we initialized two arrays differently
i.e (names and years)
*/

//Accessing arrays 

             ↗️//var name of the array
console.log(names);
//console prints ['Ozil','Fabregas','Sanchez'];
console.log(years)
//console prints [2013, 2006,2015]  

//Accessing  Array elements
console.log(names[0]); ➡️ // Ozil
console.log(years[1] ; ➡️ // 2006

Notes from the above snippet

📍 Arrays can be retrieved by calling their respective variable names as(names and years) were called through the console

📍 Array elements (entries/data) can be accessed by calling the variable name of such array and hitherto adding the index of the intended entry in a square bracket after it. e.g names[0] to get the first element in the array