0

For example, I have an object:

var model = {user:{name: 'Mike', phones:{mobile: '00000'}}};

and a string key:

var string_key = 'user.phones.mobile';

I can parse it to get the array key:

var keys = string_key.split('.');

How can I can get link to object phones from model?

Lix
  • 47,311
  • 12
  • 103
  • 131
falloff
  • 245
  • 3
  • 10
  • 1
    possible duplicate of [Accessing nested JavaScript objects with string key](http://stackoverflow.com/questions/6491463/accessing-nested-javascript-objects-with-string-key) – hsz Sep 03 '14 at 11:20
  • I write it http://jsfiddle.net/yvb5a8y6/ with updating last key data – falloff Sep 03 '14 at 11:44

1 Answers1

-1

By doing this:

model[keys[0]][keys[1]][keys[2]];

This seems a bit strange though..

heikkim
  • 2,955
  • 2
  • 24
  • 34