I'm creating an associative array (technically an object) like this, and the keys should be strings.
var j = <?php echo $max_key ?>;
var id = "ele"+j;
eleDetailsTop[id] = {id: id, size : "100%", sizeLabel : 12};
Finally this object will be stored in the DB as a JSON string.
My problem is generating a value for j. Keys will look like this ele0, ele1, ele2...
etc. So, value of j
It should be +1
from the max value of the currently stored keys in the DB. Let's say the max value is ele4
, the next value of j
should be 5
. So, then I can generate new id as ele5
How to get this done ?
var max = <?php echo $max_key ?>;
var eleDetailsTop = [];
for (var id = 0; id < max; id++) {
eleDetailsTop["ele" + id] = {id: id, size : "100%", sizeLabel : 12};
}