2015년 4월 28일 화요일

JavaScript에서의 PHP print_r | PHP print_r in JavaScript

PHP’s print_r, dump in JavaScript


Array

var array = {
  'a': 1,
  'b': 2,
  'c': {
    '1': '!',
    '2': '@'
  },
  'd': ['A', 'B', 'C']
};

Case 1

console.log(array);

enter image description here

Case 2

console.log(JSON.stringify(array));
{"a":1,"b":2,"c":{"1":"!","2":"@"},"d":["A","B","C"]}

Case 3

console.log(JSON.stringify(array, null, 2));
{
  "a": 1,
  "b": 2,
  "c": {
    "1": "!",
    "2": "@"
  },
  "d": [
    "A",
    "B",
    "C"
  ]
}

댓글 없음:

댓글 쓰기