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
  • 857,932
  • 118
  • 1,152
  • 1,264
Andrei Surdu
  • 2,196
  • 3
  • 21
  • 31

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
  • 138,711
  • 129
  • 435
  • 755