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

21st Jan 2021, 1:49 PM
Uchiha
9 Antworten
22nd Jan 2021, 3:22 AM
Calviղ
Calviղ - avatar
+ 4
Hmmmm thats a good alternative bro good job Edit: use JSON.stringify(object, null, 4) This will give you formatted output
22nd Jan 2021, 3:35 AM
Krish
Krish - avatar
+ 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
21st Jan 2021, 2:30 PM
Krish
Krish - avatar
+ 3
Calviղ That will print at the time id creation you can better make a function to print
22nd Jan 2021, 2:26 AM
Krish
Krish - avatar
+ 2
Uchiha Write each line for each object you can't access all objects at once
21st Jan 2021, 5:03 PM
Krish
Krish - avatar
+ 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
21st Jan 2021, 11:06 PM
Calviղ
Calviղ - avatar
+ 2
Calviղ Thanks so much I finally understand
22nd Jan 2021, 9:17 AM
Uchiha
+ 1
console.log(JSON.stringify(sheep))
21st Jan 2021, 2:07 PM
Calviղ
Calviղ - avatar
+ 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
21st Jan 2021, 4:17 PM
Uchiha