What's the right way to access the data from a JavaScript object? -
this question has answer here:
i have object:
var messages = { "msg100": "message 100", "msg101": "message 101", "msg102": "message 102", "msg103": "message 103", }
if want msg101
can using of these 2 methods:
messages.msg101 // or messages['msg101']
both return same value. so, method better use , why?
the first 1 more limited ( btw i'm sure it's dup).
var messages = { "1": "message 103" } alert(messages.1) //nope
as opposed :
var messages = { "1": "message 103" } alert(messages["1"]) //all ok
Comments
Post a Comment