العودة إلى الدورة

Introduction to Arrays: Ordered Lists of Data

JavaScript: الدورة الكاملة للمبتدئين من 'الصفر إلى الاحتراف'

52. Introduction to Arrays

An Array is a special type of object used to store multiple values in a single variable. The values are ordered and accessed via a numeric index.

Defining Arrays

Arrays are defined using square brackets [].

javascript // An array of strings const fruits = ['Apple', 'Banana', 'Cherry'];

// An array can hold different data types const mixedData = [10, 'Text', true, null];

// An empty array const emptyList = [];

Array Indices (Zero-Based)

Arrays are zero-indexed, meaning the first element is at index 0, the second at index 1, and so on.

javascript const names = ['Anna', 'Bob', 'Chris'];

console.log(names[0]); // Output: Anna console.log(names[2]); // Output: Chris

// Accessing an index outside the array returns undefined console.log(names[5]); // Output: undefined