2016-07-15 2 views
-3

두 라인이 서로 다른 출력을 제공하는 이유 출력console.log와 document.write가 동일한 코드에 대해 다른 출력을주는 이유는 무엇입니까? 다음

var myArray = ["one", "two","three", "four"]; 
var arr = [myArray]; 
console.log(arr);    //ouput - [Array[4]] 
window.document.write(arr);  //ouput - one,two,three,four 

와 코드인가? 미리 감사드립니다.

+0

'에 대한은 Array.toString()를 사용할 수 있습니다. –

+1

적어도 물어보기 전에 Google에서 검색 한 것처럼 보이게 할 수 있습니다. – RDardelet

답변

3

console.log은 Array 또는 Object 또는 자바 스크립트 데이터의 구조를 알 수 있습니다. 그래서 제대로 인쇄합니다. 이 one,two,three,four

window.document.write(arr.toString() // one,two,three,four 
0

document.write를 인쇄 .SO

console.log(myArray) // ["one", "two", "three", "four"] 

동안, document.write는() 배열에 있으며, toString()를 호출 그것을 (arr)toString() 메소드를 호출합니다.

당신은 콘솔 벤더 스타일 일 wheras의`toString` 메소드를 호출 document.write` 같은 결과

관련 문제