«   2019/02   »
          1 2
3 4 5 6 7 8 9
10 11 12 13 14 15 16
17 18 19 20 21 22 23
24 25 26 27 28    
Archives
Today
151
Total
1,199,054
안정적인 DNS서비스 DNSEver
관리 메뉴

Blue Breeze

javascript object 값 출력 본문

FrontEnd/JavaScript

javascript object 값 출력

푸른바람 C/H 2010.03.10 04:30
dump: function(arr,level) {
	var dumped_text = "";
	if(!level) level = 0;
	
	//The padding given at the beginning of the line.
	var level_padding = "";
	for(var j=0; j < level+1; j++) level_padding += "    ";
	
	if(typeof(arr) == 'object') { //Array/Hashes/Objects 
		for(var item in arr) {
			var value = arr[item];
			
			if(typeof(value) == 'object') { //If it is an array,
				dumped_text += level_padding + "'" + item + "' ...\n";
				dumped_text += this.dump(value,level+1);
			} else {
				dumped_text += level_padding + "'" + item + "' => \"" + value + "\"\n";
			}
		}
	} else { //Stings/Chars/Numbers etc.
		dumped_text = "===>"+arr+"<===("+typeof(arr)+")";
	}
	return dumped_text;
}


핵심은 for(var item in arr)

어디서 퍼 왔는지 당췌 기억이.. ^^;;;
2 Comments
댓글쓰기 폼