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]}
jcubic
  • 61,973
  • 54
  • 229
  • 402
LeBlaireau
  • 17,133
  • 33
  • 112
  • 192
  • what do these functions? this feels like an example where one function with an argument would be the better solution. – Thomas Apr 22 '16 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. – LeBlaireau Apr 22 '16 at 11:12

1 Answers1

5

Use bracket notation on window object:

window['total' + daysoftheweek[0]]()
jcubic
  • 61,973
  • 54
  • 229
  • 402