user147 user147 - 5 months ago 24
Javascript Question

Javascript dynamic variable name

I need something like this.

var thing_<?php echo $php_var->n ?> = <?php echo '32' ?>


want to create something like this :

var thing_342 = '32'

Answer

You need an object, and use it as an associative array/hash/whatever you are used to call it.

var thing = {};
thing[342] = '32';

or

var thing = {342: '32'};
Comments