Sobes.tech
Intern

What is an array?

sobes.tech AI

Answer from AI

An array is an ordered collection of elements, accessible by a numerical index.

Main characteristics:

  • Elements are stored sequentially in memory.
  • Accessing any element takes the same amount of time (O(1)) due to direct address calculation by index.
  • It can store elements of the same or different data types (depending on the programming language).
  • The size can be fixed or dynamic.

Example in JavaScript:

// Creating an array of numbers
const numbers = [1, 2, 3, 4, 5];

// Accessing an element by index
console.log(numbers[0]); // Outputs: 1

// Adding an element (for dynamic arrays)
numbers.push(6);

// Array length
console.log(numbers.length); // Outputs: 6