title: Javascript Dynamically Change Object Values
body: <p>I have an object like this</p>
  
  <pre><code>var userobj = {
      user1: {
          firstName: 'abc',
          lastName: 'abc', 
          age: 29,
          address: {
              company: {
                  location: 'xyz',
                  city: 'xyz',
                  street: 'xyz',
                  city: 'xyz'
              },
              location: 'xyz',
              city: 'xyz',
              street: 'xyz',
              city: 'xyz'
          },
          payment: {
              visa: false,
              master: false,
              paypal: true
          },
  
      },
  
      user2: {
          firstName: 'abc',
          lastName: 'abc', 
          age: 29,
          address: {
              company: {
                  location: 'xyz',
                  city: 'xyz',
                  street: 'xyz',
                  city: 'xyz'
              },
              location: 'xyz',
              city: 'xyz',
              street: 'xyz',
              city: 'xyz'
          },
          payment: {
              visa: false,
              master: false,
              paypal: true
          }
      }
  };
  </code></pre>
  
  <p>I want to write a function to change the data dynamically like this Funtkion</p>
  
  <pre><code>function updateUserData(userName, key, value) {
      userobj[userName][key] = value;
  }
  </code></pre>
  
  <p>This works if  only to change the first level key</p>
  
  <pre><code>updateUserData('user1', 'firstName', 'David');
  </code></pre>
  
  <p>can someone tell me how I can change the function so that I can change key into other levels too? Perhaps with an array as parameter? Like this</p>
  
  <pre><code>updateUserData('user1', ['address', 'company', 'location'], 'David');
  </code></pre>