user147 user147 - 2 years ago 159
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 Source

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

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


var thing = {342: '32'};
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download