You can create a static array and store it on your constructor function:
MyClass.allInstances = [];
MyClass.allInstances.push(this);
However, you need some way to figure out when to remove instances from this array, or you’ll leak memory.
More Related Contents:
- Why don't we use JavaScript objects to store data instead of MySQL or any database? [closed]
- Dynamically access object property using variable
- Private properties in JavaScript ES6 classes
- Why is null an object and what’s the difference between null and undefined?
- Remove array element based on object property
- javascript document.getElementsByClassName compatibility with IE
- Call static methods from regular ES6 class methods
- How to check if object property exists with a variable holding the property name?
- Generic deep diff between two objects
- Print content of JavaScript object? [duplicate]
- Adding custom properties to a function
- Getting the object’s property name
- JavaScript – Owner of “this”
- Is there any way to use a numeric type as an object key?
- Why duck typing is allowed for classes in TypeScript
- ES6 classes : what about instrospection?
- requestAnimationFrame with this keyword
- Pure Javascript – store object in cookie
- Group by, and sum, and generate an object for each array in JavaScript
- How do I access properties of a javascript object if I don’t know the names?
- Filtering array of objects by searching nested object properties
- Is there any possibility to have JSON.stringify preserve functions?
- Dynamic deep setting for a JavaScript object [duplicate]
- getting the last item in a javascript object
- What are getters and setters for in ECMAScript 6 classes?
- Sort Keys in Javascript Object
- How to prevent automatic sort of Object numeric property?
- Javascript / Chrome – How to copy an object from the webkit inspector as code
- What’s the JavaScript’s Object.prototype behavior?
- Why is “forEach not a function” for this object?