반응형
Chrome 콘솔에서 전체 개체를 표시하는 방법은 무엇입니까?
var functor=function(){
//test
}
functor.prop=1;
console.log(functor);
이것은 functor의 기능 부분만을 보여 주며 콘솔에서 functor의 속성을 보여줄 수 없습니다.
다음 과 같이 버전 console.dir()
대신 클릭 할 수있는 찾아보기 가능한 객체를 출력하는 데 사용하십시오 .toString()
.
console.dir(functor);
지정된 객체의 JavaScript 표현을 인쇄합니다. 기록중인 객체가 HTML 요소 인 경우 DOM 표현의 속성이 인쇄됩니다 [1]
[1] https://developers.google.com/web/tools/chrome-devtools/debug/console/console-reference#dir
다음을 시도하면 더 나은 결과를 얻을 수 있습니다.
console.log(JSON.stringify(functor));
다음을 시도하면 더 나은 결과를 얻을 수 있습니다.
console.log(JSON.stringify(obj, null, 4));
var gandalf = {
"real name": "Gandalf",
"age (est)": 11000,
"race": "Maia",
"haveRetirementPlan": true,
"aliases": [
"Greyhame",
"Stormcrow",
"Mithrandir",
"Gandalf the Grey",
"Gandalf the White"
]
};
//to console log object, we cannot use console.log("Object gandalf: " + gandalf);
console.log("Object gandalf: ");
//this will show object gandalf ONLY in Google Chrome NOT in IE
console.log(gandalf);
//this will show object gandalf IN ALL BROWSERS!
console.log(JSON.stringify(gandalf));
//this will show object gandalf IN ALL BROWSERS! with beautiful indent
console.log(JSON.stringify(gandalf, null, 4));
이것은 나를 위해 완벽하게 작동했습니다.
for(a in array)console.log(array[a])
찾기 / 바꾸기 정리 및 추출 된이 데이터의 사후 사용을 위해 콘솔에서 생성 된 배열을 추출 할 수 있습니다.
콘솔에 물건을 편리하게 인쇄하는 기능을 작성했습니다.
// function for debugging stuff
function print(...x) {
console.log(JSON.stringify(x,null,4));
}
// how to call it
let obj = { a: 1, b: [2,3] };
print('hello',123,obj);
콘솔에서 출력됩니다 :
[
"hello",
123,
{
"a": 1,
"b": [
2,
3
]
}
]
최신 브라우저를 사용하면 console.log(functor)
완벽하게 작동합니다 (와 동일하게 작동 함 console.dir
).
Trident D' Gao의 답변을 작성했습니다.
function print(obj) {
console.log(JSON.stringify(obj, null, 4));
}
사용 방법
print(obj);
obj를 출력하려면 :
console.log(obj, null, 4)
참고 URL : https://stackoverflow.com/questions/4482950/how-to-show-full-object-in-chrome-console
반응형
'Programing' 카테고리의 다른 글
jquery를 통해 앵커 클릭을 어떻게 시뮬레이트 할 수 있습니까? (0) | 2020.06.16 |
---|---|
공분산과 역 분산의 차이 (0) | 2020.06.16 |
Laravel 5 이메일을 사용하려고합니다 (0) | 2020.06.15 |
구성 파일에서 ng serve의 기본 호스트 및 포트 설정 (0) | 2020.06.15 |
OpenCV2.0 및 Python2.6으로 이미지 크기를 조정하는 방법 (0) | 2020.06.15 |