97.7k views
0 votes
In Js how will you declare and intialize an obejct an array

1 Answer

2 votes

Answer:

In Javascript array are the special type of object ,to store the multiple value in single variable we used array in javascript .

Step-by-step explanation:

We can create an array in javascript by using following syntax

var arrayname=[value1,value2.........valuen];

For example :

var st=["san","ran",tan"];

In javascript array are treated as object.

we can declare and initialize an object of array

var st=["san","ran",tan"]; // declaring array

document.getElementById("d2").innerHTML = st[0]; // accessing the member of array by array object.

In this st object access the first element in the array .

Following are implementation of declare and initialize an object an array

<html>

<body>

<p id="d2"></p>

<script>

var st=["san","ran",tan"];

document.getElementById("d2").innerHTML = st[0];

</script>

</body>

</html>

Output:

san

User Micapam
by
5.4k points