Js attribute problem: although both obj.an and obj ['a'] obtain attribute values, there must be relative differences. I don't know what the difference is.

I"d like to find out what the differences are

.
Mar.23,2021

for example, I have a strange property name

var a = {
  'b-1': 2
}
a['b-1']  // 

for example, I need to get

dynamically.
var obj = {
    a: '1',
    b: '2'
}

function getValue(key) {
    return obj[key]  // 
} 

getValue('a')
getValue('b')


the standard universal method is actually in the form of a [] . The format of . is only used for individual string attributes (methods) of names determined in advance

.
Menu