Reputation: 275
I want to concatenate an object property to a variable like this,
var foo = { bar_zen: 0, bar_jj: 0 }
var foo2 = $(this); // this comes from attr of an Id or class on click
if(foo.bar_+foo2+ == 0){ ..// do something }
Upvotes: 0
Views: 499
Reputation: 4209
use bracket notation instead of dots:
if(foo["bar_" + foo2] == 0){ ..// do something }
Upvotes: 1