-1

Here is a object declaration: var o = {"foo-bar": 24} Then, my question is how to access the property?


I forget it that I can access a object's property by using square brackets...

HBP
  • 15,010
  • 6
  • 26
  • 34
YON
  • 1,507
  • 3
  • 16
  • 32

2 Answers2

3

Use square brackets:

o['foo-bar']
RichieHindle
  • 258,929
  • 46
  • 350
  • 392
1
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Untitled Document</title>
</head>

<body>

<script type="text/javascript">
    var o = {"foo-bar": 24};
    alert(o['foo-bar']);
</script>
</body>
</html>
Harsha Venkatram
  • 2,782
  • 1
  • 31
  • 57