Marven Wilson S Donque
Marven Wilson S Donque

Reputation: 275

How to concatenate an object property to another string or variable in javascript

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

Answers (1)

nvioli
nvioli

Reputation: 4209

use bracket notation instead of dots:

if(foo["bar_" + foo2] == 0){ ..// do something }

Upvotes: 1

Related Questions