LeBlaireau
LeBlaireau

Reputation: 17467

Javascript variable substitution

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]}

Upvotes: 0

Views: 123

Answers (1)

jcubic
jcubic

Reputation: 66488

Use bracket notation on window object:

window['total' + daysoftheweek[0]]()

Upvotes: 5

Related Questions