0% found this document useful (0 votes)
5 views2 pages

JavaScript Array

JavaScript arrays are a versatile data type used to store lists of values, including various data types and even other arrays. They can be accessed and modified using their index, and come with built-in methods for manipulation, such as push, pop, and map. Arrays are mutable, allowing for changes to their elements after creation.

Uploaded by

kvishal88567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
5 views2 pages

JavaScript Array

JavaScript arrays are a versatile data type used to store lists of values, including various data types and even other arrays. They can be accessed and modified using their index, and come with built-in methods for manipulation, such as push, pop, and map. Arrays are mutable, allowing for changes to their elements after creation.

Uploaded by

kvishal88567
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 2

JavaScript

Array
JavaScript arrays are a data type used to store a list of values. They can hold various data
types, including strings, numbers, Booleans, and even other arrays. Arrays are a special type
of object in JavaScript, and they are used to store multiple values in a single variable.
Example

const name = [“Rahul”, “Aman”, “Raj”];

const data = [12, “Akash”, false];

Accessing Array Elements


Array elements can be accessed using their index, which starts at 0. For example:

const arr = [1, 2, 3];


console.log(arr[0]);

Modifying Array Elements


Array elements can be modified by assigning a new value to their index. For example:

const arr = [1, 2, 3];


arr[0] = 10;
console.log(arr); // Output: [10, 2, 3]

Note: Array are mutable it can be change.

Array Methods
JavaScript arrays have several built-in methods that can be used to manipulate and
transform the array. Some common methods include:

• push(): Adds one or more elements to the end of the array.


• pop(): Removes the last element from the array.
• shift(): Removes the first element from the array.
• unshift(): Adds one or more elements to the beginning of the array.
• splice(): Removes or replaces elements in the array.
• slice(): Returns a subset of the array.
• concat(): Merges two or more arrays into a new array.
• join(): Converts the array into a string.
• forEach(): Executes a function for each element in the array.
• map(): Creates a new array with the results of applying a function to each element in
the array.
• filter(): Creates a new array with the elements that pass a test implemented by a
function.
• reduce(): Applies a function against an accumulator and each element in the array
(from left to right) to reduce it to a single value.

You might also like