0

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 }
1
  • 1
    Show the corresponding HTML as well. Also, $(this) does not correlate to an attribute or an id. It references an object. Commented Jul 7, 2017 at 19:00

1 Answer 1

1

use bracket notation instead of dots:

if(foo["bar_" + foo2] == 0){ ..// do something }
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.