Anthony
Anthony

Reputation: 1

How to link the function of a button to a single marker of an array

I have an array with 20 element like this:

they are showed on the map with a green marker, but I want that when i click on the button and some property are respected, the marker turns red. The problem is that when i change the color, every marker turns red and not only one. So, how can I set the function for only one element based on property?

const array = [
{ text: "something1",
  coordinates: "something2"
},
...
];

function do(){
//what the function should do
}

Upvotes: -1

Views: 56

Answers (1)

Qiimiia
Qiimiia

Reputation: 607

Try adding a property e.g. colour for every object in your array:

array .forEach(obj => obj.color = 'green')

Then in your function, add a condition to change the 'green' property to 'red' only for objects that are clicked

Upvotes: 0

Related Questions