Make Money Online HTML PHP JAVASCRIPT ARRAY pada JAVASCRIPT : Intro

ARRAY pada JAVASCRIPT : Intro

ARRAY pada JAVASCRIPT : Intro post thumbnail image



to Array in JavaScript

An array is a data structure that allows you to store multiple values in a single variable. You can think of an array as a list of items, where each item is identified by an index number.

You can create an array in JavaScript by using the Array constructor:

var myArray = new Array();

You can also create an array by using the Array literal notation:

var myArray = [1, 2, 3, 4, 5];

The Array constructor and the Array literal notation both create an array that has five elements. The first element is at index 0, the second element is at index 1, and so on.

You can access the values in an array by using the index number of the element you want to access. For example, if you want to access the third element in an array, you would use the following code:

var myArray = [1, 2, 3, 4, 5];

var thirdElement = myArray[2];

The code above would assign the value “3” to the thirdElement variable.

You can also use the for…in loop to access the values in an array. The for…in loop will iterate through all of the elements in an array, and it will assign the index number of each element to the variable. For example, the following code will print the values of all of the elements in the myArray array:

var myArray = [1, 2, 3, 4, 5];

for (var i = 0; i < myArray.length; i++) { console.log(myArray[i]); } The code above will print the following values: 1 2 3 4 5

Related Post