What is different between array and acces by index?

both work like same but array is quite difficult to understand but acces by index is quite easy

Does this question relate to an exercise?

We know that an array is an ordered data structure that is linear from left to right. An array may be empty.

arr = new Array();
console.log(arr)                     // []
console.log(Array.isArray(arr))      // true
console.log(arr instanceof Array);   // true

Polling an array element will return undefined if it finds nothing at the index specified, whether it exists or not…

console.log(arr[0])                  //  undefined
console.log(arr[10])                 //  undefined

An array can be defined with a length, yet have no data.

arr = new Array(10);
console.log(arr.length);             // 10
arr.push(10);
console.log(arr[10]);                // 10
console.log(arr[9]);                 // undefined

An array is not type bound. It may contain any data type, including objects, other arrays and functions.

Eg.
 > arr.push((a,b) => {return a + b})
<- 1
 > arr.push((a,b) => {return a - b})
<- 2
 > arr.push((a,b) => {return a * b})
<- 3
 > arr.push((a,b) => {return a / b})
<- 4
 > arr
<- (4) [Ć’, Ć’, Ć’, Ć’]
  > 0: (a,b) => {return a + b}
  > 1: (a,b) => {return a - b}
  > 2: (a,b) => {return a * b}
  > 3: (a,b) => {return a / b}
    length: 4

 > arr[3](42, 6)
<- 7

Here is my understanding:

An array is a collection of data, whether it be of characters, strings, integers, floating point numbers (reals), or perhaps even objects. This data is represented as being stored in memory sequentially as shown below:

array            => | 0  | 1  | 2  | 3  | 4  | 5  | 6  | 7  | 8  |  
visualized         `````````````````````````````````````````````````````

Each numbered slot contains some data that you store in it throughout the program, or initialized it with at the beginning of the program. “Access by Index” is the manner in which the data inside of the array is accessed. If slot zero has data you need, you would “access it by its index” – array[0]. And so on for other indices.

2 Likes