0
How to print all the objects created using a particular object constructor in Javascript
An object constructor can have hundreds or even thousands of objects created from it. Is there any way to print all of them in Javascript? Any help would be greatly appreciated. To understand my question better please have a look at this code https://code.sololearn.com/W831Au61qIR0/?ref=app
9 ответов
+ 4
+ 4
Hmmmm thats a good alternative bro good job
Edit: use JSON.stringify(object, null, 4)
This will give you formatted output
+ 3
First of all close the comment at last with */ as it gives an error
Just write
console.log(JSON.stringify(sheep, null, 4)) ;
This will print the json in formatted way
+ 3
Calviղ
That will print at the time id creation you can better make a function to print
+ 2
Uchiha
Write each line for each object you can't access all objects at once
+ 2
Add console.log(JSON.stringify(sheep)) in the function.
function mob(id,name,type){
this.id=id;
this.name=name;
this.type=type
console.log(JSON.stringify(this))
}
https://code.sololearn.com/Wcq9vWc2G8gK/?ref=app
+ 2
Calviղ Thanks so much I finally understand
+ 1
console.log(JSON.stringify(sheep))
+ 1
Krish [less active] This helps a bit but how can I use this to print all the objects created by the mob constructor and their properties