JavaScript version of var_dump

[et_pb_section admin_label=”section”][et_pb_row admin_label=”row”][et_pb_column type=”4_4″][et_pb_text admin_label=”Text” background_layout=”light” text_orientation=”left” use_border_color=”off” border_color=”#ffffff” border_style=”solid”]

<script>
function dump(obj) {
  var out = '';
  for (var i in obj) {
    out += i + ": " + obj[i] + "\n";
  }
  alert(out);
}
</script>

// or, if you wanted to avoid alerts and var_dump() on the page…

<script>
function dump(obj) {
  var out = '';
  for (var i in obj) {
    out += i + ": " + obj[i] + "\n";
  }
var pre = document.createElement('pre');
  pre.innerHTML = out;
  document.body.appendChild(pre)
}
</script>

// or var_dump() to the console…

<script>
function dump(obj) {
  var out = '';
  for (var i in obj) {
    out += i + ": " + obj[i] + "\n";
  }
  console.log(out);
}
</script>

 

[/et_pb_text][/et_pb_column][/et_pb_row][/et_pb_section]