0

I have an array

daysoftheweek:['Monday', 'Tuesday','Wednesday', 'Thursday', 'Friday','Saturday', 'Sunday'],

Also I have functions

function totalMonday() {}
function totalTuesday() {}

Can I use variable substitution to call them?

total+{daysoftheweek[0]}
2
  • what do these functions? this feels like an example where one function with an argument would be the better solution. Commented Apr 22, 2016 at 11:04
  • they are actually vuejs computed values but you are right, I created a method thay takes a couple of params. Although the answer is correct I feel it is a bit messy. Commented Apr 22, 2016 at 11:12

1 Answer 1

5

Use bracket notation on window object:

window['total' + daysoftheweek[0]]()
Sign up to request clarification or add additional context in comments.

Comments

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.