2

I have this object:

var Messages = {
    "msg100": "Message 100",
    "msg101": "Message 101",
    "msg102": "Message 102",
    "msg103": "Message 103",
}

If I want to get msg101 I can do it using any of these two methods:

Messages.msg101
// or
Messages['msg101']

Both return the same value. So, what method is better to use and why?

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
Andrei Surdu
  • 2,281
  • 3
  • 23
  • 32

1 Answers1

-1

The first one is more limited ( BTW i'm sure it's a dup).

var Messages = {

    "1": "Message 103"
}

alert(Messages.1) //nope

As opposed to this :

var Messages = {

    "1": "Message 103"
}

alert(Messages["1"]) //all ok
Royi Namir
  • 144,742
  • 138
  • 468
  • 792