When receiving JSON data from AJAX, I often find myself working with multiple variables. For example, I may have data stored in variables like data.output_data_1234 and data.output_data_5678.
To work with these variables more effectively, I convert them to arrays. This can be achieved with the following code:
var outputdataarr = new Array(data.output_data_1234);
While this method works well, I sometimes encounter the need to add a number to the variable name. I attempted the following code, but unfortunately, it did not yield the desired result:
var outputdataarr = new Array('data.output_data_'+formid+'');
It's important to note that formid contains a valid number.
Another approach I tried was accessing the variable using window[] syntax, as shown below. However, this method also did not provide the expected outcome:
var outputvar = window['data.output_data_' + formid];
var outputdataarr = new Array(outputvar);
If you have any insights or suggestions on how to tackle this issue, I would greatly appreciate your help. Thank you in advance!