JavaScript Arrays are a collection of data items. They allow you to store multiple values in a single variable. You can store different types of data in an array, like strings, numbers, objects, and even other arrays.
JavaScript Arrays are a data structure that can store multiple values in a single variable. They are written as a list of values separated by commas and enclosed in square brackets ([]
).
For example:
let fruits = ["apple", "banana", "cherry"];
Array Properties:
length
: Represents the number of elements in an array.constructor
: Represents the constructor function that creates an array.Array Methods:
concat(array1, array2, ...)
: Merges two or more arrays into a single array.join(separator)
: Converts all elements in an array into a string, separated by the specified separator
.pop()
: Removes the last element from an array and returns it.push(element1, element2, ...)
: Adds one or more elements to the end of an array and returns the new length.reverse()
: Reverses the order of elements in an array.shift()
: Removes the first element from an array and returns it.slice(start, end)
: Extracts a section of an array and returns a new array.sort()
: Sorts the elements of an array in place.