Access non-numeric Object properties by index?

前端 未结 9 2413
时光取名叫无心
时光取名叫无心 2020-11-27 03:41

If I have an array like this:

var arr = [\'one\',\'two\',\'three\'];

I can access different parts by doing this:

console.lo         


        
9条回答
  •  忘掉有多难
    2020-11-27 03:55

    you can create an array that filled with your object fields and use an index on the array and access object properties via that

    propertiesName:['pr1','pr2','pr3']
    
    this.myObject[this.propertiesName[0]]
    

提交回复
热议问题