Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
这是一个对象声明:var o = {"foo-bar": 24} 那么,我的问题是如何访问该属性?
var o = {"foo-bar": 24}
我忘记了我可以通过使用方括号来访问对象的属性......
使用方括号:
o['foo-bar']
<!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>