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.

<!DOCTYPE html>

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

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"];



Leave a Reply