Home > Web Front-end > JS Tutorial > Detailed explanation of js console.log printing object and array usage_javascript skills

Detailed explanation of js console.log printing object and array usage_javascript skills

WBOY
Release: 2016-05-16 15:18:57
Original
1555 people have browsed it

The example in this article describes the usage of js console.log printing objects and arrays. Share it with everyone for your reference, the details are as follows:

What is console.log? It is actually a function that prints js arrays and objects, just like PHP's print_r and var_dump. There is nothing much to say about the console.log function itself. This blog will tell you how to use this function. Before talking about this function, I think the most commonly used one to check js output is alert, but alert can only play string or int

1. Test file test.html

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>console.log test</title>
</head>
<script type="text/javascript">
var testobj =
  {
    'id': 1,
    'content': 'test',
    'firstname': function() {
      document.getElementById('firstname').value = "zhang";
    },
    'lastname': function() {
      document.getElementById('lastname').value = "ying";
    }
  };
<!-- 打印对像 -->
  console.log(testobj);
</script>
<body>
   <input type="text" id='firstname' name="firstname" value=''>
   <input type="text" id='lastname' name='lastname' value=''>
</body>
</html>

Copy after login

2. View js objects using chrome development tools

console chrome

Now when I use chrome developer tools and firebug, they are half and half. Chrome developer tools also have a feature that firebug does not have.

The console can run js. If the page is an iframe, firebug can only run on the parent, and chrome can choose the page inside to execute, as shown below

chrome iframe console

3. View js objects in firebug

firebug console

Readers who are interested in more content related to JavaScript arrays can check out the special topic on this site: "Summary of JavaScript array operation skills"

I hope this article will be helpful to everyone in JavaScript programming.

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template