Last active
August 29, 2015 13:56
-
-
Save glebcha/8819424 to your computer and use it in GitHub Desktop.
Parse JSON array and create multi-dimensional array
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var jsonObj = [{"forget":"me","leave":"alone"}, {"take":"them", "not":"him"}]; | |
var arr = []; | |
for(var i = 0; i < jsonObj.length; i++) { | |
var val = jsonObj[i]; | |
var def = Object.keys(val); | |
//console.log("all keys: " + def); | |
for(var j = 0; j < def.length; j++) { | |
arr.push([ def[j], val[def[j]] ]); | |
} | |
} | |
console.log(arr);//will output [Array[2], Array[2], Array[2], Array[2]] | |
console.log(arr[0]);//will output ["forget", "me"] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment