Mixed Arrays
The mixed arrays in JavaScript can contain elements of multiple data types stored at contiguous memory location with same name that can be accessed using the indexing syntax.
Example: The below code is the practical implementation of the mixed arrays in JavaScript.
Javascript
const mixedArr = [ [1, 2, 3], "w3wiki" , 23, { cricketer: "Virat Kohli" } ]; console.log( "Array element: " , mixedArr[0]); console.log( "String element: " , mixedArr[1]); console.log( "Number element: " , mixedArr[2]); console.log( "Object element: " , mixedArr[3]); |
Output
Array element: [ 1, 2, 3 ] String element: w3wiki Number element: 23 Object element: { cricketer: 'Virat Kohli' }
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