0

I have a variable multiple variables that end differently such as

fibrecementrustedorpoppedfixings

fibrecementrustedorpoppedfixingsprice

fibrecementrustedorpoppedfixingsunits

fibrecementrustedorpoppedfixingsrange

I'm looking for a way to be able to just use the main variable then add the last part on where needed in the function something like

fibrecementrustedorpoppedfixings + price would print the value of fibrecementrustedorpoppedfixingsprice

NZLRhyz
  • 3
  • 1

1 Answers1

-1

What you're looking for is eval():

var fibrecementrustedorpoppedfixingsprice = 23;
console.log(eval("fibrecementrustedorpoppedfixings" + "price"));

However, note that eval() can be evil, as it:

  • requires a compile (and is therefore slow)
  • can execute malicious arguments
  • inherits execution scope

As such, it should only be used with caution.

Hope this helps! :)

Obsidian Age
  • 41,205
  • 10
  • 48
  • 71