Skip to content

Instantly share code, notes, and snippets.

@lbj96347
Created March 6, 2012 14:10
Show Gist options
  • Save lbj96347/1986476 to your computer and use it in GitHub Desktop.
Save lbj96347/1986476 to your computer and use it in GitHub Desktop.
Restructuring JSON
var m = [{a:'a',b:'b'},{a:'c',b:'d'}];
//regard m as a JSON
var img = new Array();
for (x in m )
{
var val = m[x].a;
img[x]={img:val,name:val}
}
//img[0]={img:'a', name :'a'}
//img[1]={img:'c', name :'c'}
//this is the result we want to get.
console.log(img);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment