-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,685
  • 6
  • 28
  • 34
YON
  • 1,607
  • 3
  • 18
  • 33

2 Answers2

3

Use square brackets:

o['foo-bar']
RichieHindle
  • 272,464
  • 47
  • 358
  • 399
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 Venkataramu
  • 2,887
  • 1
  • 34
  • 58