Created
December 23, 2014 19:05
-
-
Save empirefx/c4278bb3551051a35d2b to your computer and use it in GitHub Desktop.
Iterate through json
This file contains 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
//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