I've been programming in Javascript for over 10 years now, but only in the last year or two have I started working with Javascript's OOP functionality (classes, instances, etc.). I know how to work with classes in C++ and PHP, but Javascript is a different story.

So let's say I have an array of instances of different objects. For a simplified example, say I have a class called apple() and one called orange(), and I have an array that stores many instances of both apples and oranges. There's no way to predict whether element N is an apple or an orange until it's looked at directly.

If I'm iterating through this array with a simple foreach loop, and I want to make a brand new instance of the same type as each element in the array, how would I do it? I know I can use typeof to get the object name as a string, but that doesn't help me instantiate a new instance of it.

I'm sure there's a feature of Javascript I'm missing that's the key to this. Can someone help me?