Combine a variable with variable value in Javascript

后端 未结 1 1818
没有蜡笔的小新
没有蜡笔的小新 2021-01-27 19:12

I am trying to do something like this in Angular javascript (a simplified code):

var modelName = \"date\";

if (attrs.hasOwnProperty(\'today\')) {
   scope.model         


        
1条回答
  •  陌清茗
    陌清茗 (楼主)
    2021-01-27 19:42

    You can access properties of objects using square brackets.

    var modelName = "date";
    
    if (attrs.hasOwnProperty('today')) {
       scope[modelName] = new Date();
    }
    

    0 讨论(0)
提交回复
热议问题