How to display images in the JavaScript console of the Browser & how loop through an object?
https://ourcodeworld.com/articles/read/457/how-to-display-images-in-the-javascript-console-of-the-browser
In this article, i will introduce two things:
1、how to show image in browser console
2、How to Loop Through an Object in JavaScript
第一部分:在console里面显示图片
console.image在控制台里面展示图片。
Reasonable isn’t? But, do you want to use an image instead of a style? You can do it ! In this article you will learn how to display images on the console using the console.image library.
There is no such method in the console as console.image, however thanks to the console.image library written by @adriancooney, you will be able to display images (it even supports gifs) on the console easily. To get started with this library on your project, download a copy of the minified code or the source code and add a reference to the file in your document using a script tag:
<!-- Add a reference from a local file -->
<script src="console.image.min.js"></script>
<!-- Or use a CDN -->
<script src="https://cdn.rawgit.com/adriancooney/console.image/c9e6d4fd/console.image.min.js"></script>
It’s worth to say that this only works in the console of the browser and not a terminal in the case of Node.js. After this, you will be able to access the console.image method with JavaScript.
第二部分:如何遍历一个对象
How to Loop Through an Object in JavaScript?
before introduce it, i talk about the reason why i need loop through an object。 the reason is i have an javascript json string, and i want turn this json string to create table sql, so i have to learn how to get all the key of this json. this is the reason why i need it.
in the link under , there are some methods to loop through an object。
https://learn.coderslang.com/0113-how-to-loop-through-an-object-in-javascript/#:~:text=There%20are%20four%20ways%20you%20can%20loop%20through,Object.entries%20%28%29%203%20Object.keys%20%28%29%204%20Object.values%20%28%29
they are:
for…in statement
Object.entries()
Object.keys()
Object.values()
1、An example code of for…in statement:
const object = {
Name: "John Wick",
Age: 55,
Job: "Hitman",
Nationality: "American",
};
for (const property in object) {
console.log(`${property}: ${object[property]}`);
}
2、An example code of Object.entries():
const object = {
Name: "John Wick",
Age: 55,
Job: "Hitman",
Nationality: "American",
};
Object.entries(object).forEach(([key, value]) => {
console.log(`${key}: ${value}`);
});
Object.keys and Object.values just like the Object.entries, so i don’t repeat。
so, this is what i want to say, one is console.image, another is about loop object,do you understand?