title: AngularJS update array var and non-array var whose names were obtained by string
body: <p>I'm trying to update different variables that are obtained as strings. Some are arrays, and some are not. For these values to be updated by the same function, I'd need for them to be obtained by a string. The following code only works with non-array variables.</p>
  
  <p>HTML:</p>
  
  <pre><code>Message is: {{ message }}
  &lt;button ng-click="updateVar('message')"&gt;Update&lt;/button&gt;
  &lt;br&gt;
  Message in array is: {{ messages.welcome }}
  &lt;button ng-click="updateVar('messages.welcome')"&gt;Update&lt;/button&gt;
  </code></pre>
  
  <p>AngularJS:</p>
  
  <pre><code>$scope.message = 'Simple message';
  
  $scope.messages = {
      welcome: 'Message in array'
  };
  
  $scope.updateVar = function(varToUpdate) {
      $scope[varToUpdate] = 'Var was updated!';
  };
  </code></pre>
  
  <p>How can I make this work with arrays?</p>
  
  <p>Thank you!</p>