Array as Objects

In JavaScript arrays are special type of objects and typeof operator are used to return “objects” for arrays. Array use the numbers of index values to access its data or elements and use names to access its members.

[php]
<!DOCTYPE html>
<html>
<body>

<p id="demo"></p>
<p id="demo1"></p>

<script>
var person = ["Krishna", "Singh", 26];
document.getElementById("demo").innerHTML = person[2];
var person = {firstName:"Krishna", lastName:"Singh", age:26};
document.getElementById("demo1").innerHTML = person["firstName"];
</script>

</body>
</html>[/php]
OUTPUT :



[/php]
OUTPUT :



Leave a Reply