DEV Community

Bhuvana Sri R
Bhuvana Sri R

Posted on

Array In JavaScript

what is Array ?

  • In JavaScript, an array is a single variable used to store an ordered collection of multiple values. These values, called elements, are stored at sequential positions, each identified by a numeric index. The indexing in JavaScript arrays starts at 0, meaning the first element is at index 0, the second at index 1, and so on.
  • JavaScript arrays can store elements of different data types within the same array (e.g., numbers, strings, objects, or even other arrays).
  • Unlike arrays in some other languages, JavaScript arrays are dynamic, meaning their size can change during runtime. Elements can be added or removed, causing the array to expand or shrink.

Example :

let a=["banana",1,true,"abc"]
for(int i=0;i<arr.length;i++)
{
  if(typeof(arr[i])==number)
{
console.log(arr[i]);
}
}
output:1
Enter fullscreen mode Exit fullscreen mode

Top comments (0)