Array with empty values
An array with empty values can contain the empty or blank values as the elements of the array.
Example: The below code explains the empty values array in JavaScript.
Javascript
const emptyValArray = [1, 2, , "Geek" , , 3]; console.log ( "Array with empty and other values:\n" , emptyValArray); const emptyArray = emptyValArray.filter(val => val === undefined); console.log( "Filtered Empty Array: " , emptyArray); |
Output
Array with empty and other values: [ 1, 2, <1 empty item>, 'Geek', <1 empty item>, 3 ] Filtered Empty Array: []
Types of Arrays in JavaScript
A JavaScript array is a collection of multiple values at different memory blocks but with the same name. The values stored in an array can be accessed by specifying the indexes inside the square brackets starting from 0 and going to the array length – 1([0]…[n-1]).
A JavaScript array can be classified into multiple types:
Table of Content
- Numeric Array
- String Array
- Array of Arrays (2D Arrays)
- Array of Objects
- Mixed Arrays
- Array with empty values