Skip to content

Instantly share code, notes, and snippets.

@empirefx
Created December 23, 2014 19:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save empirefx/c4278bb3551051a35d2b to your computer and use it in GitHub Desktop.
Save empirefx/c4278bb3551051a35d2b to your computer and use it in GitHub Desktop.
Iterate through json
//JQuery
function interate (arg) {
$.each(arg, function(index, value){
isObjArr = Object.prototype.toString.call( value );
if( isObjArr === '[object Object]' ) {
notThis = (index === 'this') ? "" : index;
console.log("found: object "+notThis);
interate(value);
}else if( isObjArr === '[object Array]' ) {
notInt = (index === parseInt(index)) ? "" : index;
console.log("found: array "+notInt);
interate(value);
}else{
console.log("found: "+index+":"+value);
}
});
}
var json = '{"name":"sup", "nick":"yea", "more":["more", "moreeee"], "evenmore":[["dad"],["tehet"],["testint",["yeas"]]]}';
interate($.parseJSON(json));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment