1

I have a class which creates an object. Ten of these objects are then placed in an array via a for() loop. Within the class is an if() statement defining click movement and whether the user is clicking on an object or empty space:

if (distance < this.properties.radius) {
    removeEnabled = true;
    this.manageClick();
} else {
    removeEnabled = false;
    this.properties.alpha = 0;
}

What code would I have to use to discover whether an item within the array has removeEnabled = true or if it has removeEnabled = false? Then perform separate functions for if it is true and or if it is false?

2 Answers 2

1

You could just add that removeEnabled property to your object:

obj.removeEnabled = true/false;

then you can read the obj from the array and check its removeEnabled property

Sign up to request clarification or add additional context in comments.

Comments

1

if you set

removeEnabled = true 

to

this.removeEnabled = true

it is set as a property of the object and then in your forloop you simply do this:

for (var i = 0; i < objects.length; i++) {
   if (objects[i].removeEnabled) {
       // enter required code
   }
}

3 Comments

this only acts on the last added object... I it to recognise if one of the objects in the array has removeEnabled = true then something happens
What exactly do you mean? setting the this.removeEnabled in the if statement is in the constructor code of the class right? so when you are checking the array and you check of the current object (objects[i]) if it has removeEnabled == true, then that should work for each object and not only the last. Do you otherwise have a link to your full code?
I think Daniel's answer makes a lot of sense. If you could provide more information around the "class" and the "objects" it creates, then we may be able to provide a better answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.