Arrays in Javascript
In this chapter, you will learn what is an array in Javascript. Array helps to bundle the different data types in a single variable. An Array is a collection of variables with similar data types as well as different data types. Let’s create an array.
Different ways to create an array in Javascript:
const users = ['John', 'Mark', 'Mickel']; const users2 = new Array('John', 'Mark', 'Mickel'); console.log(users); console.log(users2); // output // (3) ["John", "Mark", "Mickel"] // (3) ["John", "Mark", "Mickel"]
How to access an array element in Javascript:
An element can be accessed in the array by using the index of an element. Let’s see the below example
const users = ['John', 'Mark', 'Mickel']; const users2 = new Array('John', 'Mark', 'Mickel'); console.log(users[1]); console.log(users2[2]); // outputMark // Mark // Mickel
One thought on “Arrays in Javascript”
Comments are closed.