Access properties via bracket notation in JavaScript

Description

The following code shows how to access properties via bracket notation.

Example


<!DOCTYPE html>
<html>
<head>
<script type="text/javascript">
var tutorial = {<!--from w  ww  . ja va 2s  .c  o m-->
name : "JavaScript",
pageSize : 9
};

document.writeln(tutorial["name"]); //"JavaScript"
document.writeln(tutorial.name); //"JavaScript"

</script>
</head>
<body>
</body>
</html>

Click to view the demo

The code above generates the following result.

Access properties via bracket notation in JavaScript