Skip to content

Instantly share code, notes, and snippets.

@vnys
Created October 17, 2014 10:05
Show Gist options
  • Save vnys/d4417f95e2514e9b46cc to your computer and use it in GitHub Desktop.
Save vnys/d4417f95e2514e9b46cc to your computer and use it in GitHub Desktop.
A Pen by Victor Nystad.
var obj = { key: 'axis-x-position', value: 'numeric' };
var arr = obj.key.split('-');
for (var i = arr.length; i > 0; i--) {
arr[i-1] = Object.defineProperty({}, arr[i-1], { value: i === arr.length? obj.value : arr.pop() })
};
console.log(arr[0]);
@vnys
Copy link
Author

vnys commented Oct 17, 2014

Results in

{ 
  axis: { 
    x: { 
      position: 'numeric' 
    }
  } 
}  

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment