JavaScript – Array & Methods

1.What is an Array in JavaScript?
An array is a special type of object that can hold multiple values under a single name, and each value isstored at an index.

Index starts at 0.
You can store numbers, strings,objects, or even other arrays inside an a…


This content originally appeared on DEV Community and was authored by Dharshini E

1.What is an Array in JavaScript?
An array is a special type of object that can hold multiple values under a single name, and each value isstored at an index.

  • Index starts at 0.
  • You can store numbers, strings,objects, or even other arrays inside an array. example:
let fruits = ["Apple", "Banana", "Mango"];
console.log(fruits[0]); // Apple
console.log(fruits[2]); // Mango

2.What are Array Methods in JavaScript?
In JavaScript, array methods are built-in functionsthat you can use on arrays to perform common tasks.

Methods:

  1. push() : Add item at the end. example:
let fruits = ["Apple", "Banana"];
fruits.push("Mango"); 
console.log(fruits); // ["Apple", "Banana", "Mango"]
  1. pop() : Remove item from the end example:
fruits.pop();
console.log(fruits); // ["Apple", "Banana"]
  1. shift() : Remove item from the beginning. example:
fruits.shift();
console.log(fruits); // ["Apple", "Banana"]

4.length :
Get the size of the array.
example:

console.log(fruits.length); // 2
  1. indexOf() : Find the position of an element. example:
console.log(fruits.indexOf("Banana")); // 1

6.includes() :
Check if an element exists.
example:

console.log(fruits.includes("Apple")); // true

7.splice() :
Add/Remove elements (changes original array).
example:

nums.splice(2, 1); 
console.log(nums); // [1, 2, 4, 5]


This content originally appeared on DEV Community and was authored by Dharshini E


Print Share Comment Cite Upload Translate Updates
APA

Dharshini E | Sciencx (2025-09-01T02:42:49+00:00) JavaScript – Array & Methods. Retrieved from https://www.scien.cx/2025/09/01/javascript-array-methods-3/

MLA
" » JavaScript – Array & Methods." Dharshini E | Sciencx - Monday September 1, 2025, https://www.scien.cx/2025/09/01/javascript-array-methods-3/
HARVARD
Dharshini E | Sciencx Monday September 1, 2025 » JavaScript – Array & Methods., viewed ,<https://www.scien.cx/2025/09/01/javascript-array-methods-3/>
VANCOUVER
Dharshini E | Sciencx - » JavaScript – Array & Methods. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2025/09/01/javascript-array-methods-3/
CHICAGO
" » JavaScript – Array & Methods." Dharshini E | Sciencx - Accessed . https://www.scien.cx/2025/09/01/javascript-array-methods-3/
IEEE
" » JavaScript – Array & Methods." Dharshini E | Sciencx [Online]. Available: https://www.scien.cx/2025/09/01/javascript-array-methods-3/. [Accessed: ]
rf:citation
» JavaScript – Array & Methods | Dharshini E | Sciencx | https://www.scien.cx/2025/09/01/javascript-array-methods-3/ |

Please log in to upload a file.




There are no updates yet.
Click the Upload button above to add an update.

You must be logged in to translate posts. Please log in or register.