Arrays of Values
Explore JavaScript arrays to understand how to store and access collections of values. Learn to manipulate arrays through practical exercises including summing elements, checking for palindromes, reversing arrays, and combining values into numbers. This lesson strengthens your ability to work with array data structures in JavaScript applications.
What is an array
In JavaScript, an array is a collection of values. It is a comma-separated list of values enclosed in a pair of square brackets. An array can be stored as a single variable. For example, ["apple", "mango", "banana"] is an array of strings. It can be stored as a variable, as shown in the code below:
In the code above:
-
Line 1: We use a variable,
arrayOfFruits, to assign the comma-separated values enclosed in square brackets. -
Line 2: We list the array’s values horizontally using
console.log().
Note: When we print a complete array using
console.log(), it shows a symbol ...