Discord
Login
Community
DARK THEME

Diffrent classes in the same list. How do I check which element is what class?

I have a list, lets say: fruits = []

and two diffrent classes in it:

  fruits.push(new apple())
  fruits.push(new orange())

Now using:

 for f in fruits
   HOW DO I CHECK if f is an apple of an orange?
 end

????????

You can use .class property to check what is the type of fruit.

for f in fruits
  if f.class == apple then
    // this is an apple
  end
  if f.class == orange then
    // this is an orange
  end
end

Thanks for your help!

Post a reply

Progress

Status

Preview
Cancel
Post
Validate your e-mail address to participate in the community