Hello I have this following array:
dias = [{lunes: 0}, {martes: 0}, {miercoles: 0}, {jueves: 0}, {viernes: 0}]
I would like to simulate a reservation site and that each time a person reserves for a day the value of the property increases by one. What would be the proper way to do it?
You could do the following, list first.
Then a list of equivalences, so if you receive Monday, it will tell you what the position in the array is, you could also do this by passing the index number directly, or calculating the index by js.
Now I declare a variable just for testing.
Finally, I access days in the position that corresponds to equivalences.diaReceived, and once there, to days[0] in this case, to the Monday key, I add 1.
If we change the value of dayReceived with dayReceived = "tuesday" and cast the previous line again, then it will add 1 to the value of the Tuesday key.
I hope it works for you, without variables you would simply have to access the position where the day is in the array and make a ++ on the key Eg:
A faster way is to give it the value you need up to date with its name:
and you can add directly:
I leave you a basic example:
Maybe this will help you for your project!
Example code:
I hope I've helped!