Array
The array is the most useful data structure.
Note
A data structure is a specialized format for organizing and working with data collection. An array is a collection of items where each item is a value.
Creating an Array
To create an array, use square brackets []
:
This creates an empty array with no elements. To create an array with elements, place the elements inside []
and separate them with commas (,
):
Note
The last element in the array should not have a comma after it.
To print an array, simply use console.log()
:
Indexes
Each element in an array has a unique index.
Note
Indexes start from 0. The first element has an index of 0, the second element has an index of 1, and so on.
Accessing array data is done by specifying the index in square brackets ([index]
) after the array name:
Arrays can hold different data types, including number, string, boolean, and more.
Length Property
The length
property is a built-in property of arrays that represents the number of elements in that array. To use this property, use the following syntax:
Tudo estava claro?
Conteúdo do Curso
Introduction to JavaScript
4. Conditional Statements
Introduction to JavaScript
Array
The array is the most useful data structure.
Note
A data structure is a specialized format for organizing and working with data collection. An array is a collection of items where each item is a value.
Creating an Array
To create an array, use square brackets []
:
This creates an empty array with no elements. To create an array with elements, place the elements inside []
and separate them with commas (,
):
Note
The last element in the array should not have a comma after it.
To print an array, simply use console.log()
:
Indexes
Each element in an array has a unique index.
Note
Indexes start from 0. The first element has an index of 0, the second element has an index of 1, and so on.
Accessing array data is done by specifying the index in square brackets ([index]
) after the array name:
Arrays can hold different data types, including number, string, boolean, and more.
Length Property
The length
property is a built-in property of arrays that represents the number of elements in that array. To use this property, use the following syntax:
Tudo estava claro?