简体   繁体   English

在Chrome中检查console.log变量

[英]Inspecting console.log variables in Chrome

As a thought, i would like to know if is possible to inspect for log properties of any variable in the chrome or any other browsers within the console mode. 想一想,我想知道是否有可能检查控制台模式下chrome或任何其他浏览器中任何变量的日志属性。 As i already know that you can already inspect the DOM in inspector element and you can go through debugging mode also. 如我所知,您已经可以在检查器元素中检查DOM ,并且还可以通过调试模式。 I want to demonstrate my point and why i and most novice would benefit this. 我想说明我的观点,以及为什么我和大多数新手将从中受益。

So as you can see in the picture below: 因此,如您在下图中所看到的: 在此处输入图片说明

So as you can see i am trying to access some element of Array[15] but in the end it always giving me undefined. 因此,如您所见,我试图访问Array [15]的某些元素,但最终它总是给我未定义的信息。 It nice just to test out some code before recompiling it again which takes time. 只是在重新编译之前先测试一些代码是很不错的,这需要时间。 Plus sometime you don't always knows enough that the function you are calling in JS is compatible with what you trying to achieve. 另外,有时您对JS中调用的功能是否与您要实现的功能兼容并不总是很了解。

Put your entire code inside: 将整个代码放入其中:

$(document).ready (function (){
    //Paste your code here
});

The whole point is you are trying to access an element in the DOM before it exists. 重点是您要尝试在DOM中的元素存在之前对其进行访问。

When your trying to access the class the item doesnot exist. 当您尝试访问该类时,该项目不存在。

Alternative: Move your script below the elements in the html. 替代方法:将脚本移动到html中的元素下方。

This is a very generic solution I gave without seeing the code. 这是我提供的非常通用的解决方案,没有看到代码。 Request you to post the code as well. 也要求您发布代码。

Hope it helps. 希望能帮助到你。

You need to add a debugger where you are outputting your array. 您需要在输出数组的位置添加调试器。 It seems to me you are trying to access the variable after execution is over, so the variable value is lost, as it goes out of scope. 在我看来,您试图在执行结束后访问变量,因此变量值会丢失,因为它超出范围。 When execution stops at the debugger, you can console.log your variable and properties. 当调试器停止执行时,您可以console.log记录变量和属性。 At that point the variable will be in scope. 届时变量将在范围内。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM