How to name variables dynamically

clipboard.png

now you want to dynamically name the variable BMResulteArr_ variable
what to do?

Mar.23,2021

upstairs two big gods solve, generally rarely you operate like that, of course, if you want, you can achieve through the eval method, this method supports a parameter, pass in a string, will run the string, such as eval ('var param = "123";'); alert (param); so it will directly run the parameter string, parsed as a variable assignment.
however, it is recommended to encapsulate it in an object, so that it is relatively convenient to call, easy to set up, easy to manage, and so on.


encapsulate variables in objects


JS <br>`var ps_act_num = $('.ps_act').length;

    form_data.append('ps_act_num', ps_act_num);
    for(var i=1;i<=ps_act_num;iPP){
        var act_content = 'act_content'+i;
        var act_content_id = '-sharptextPsP5a_'+i;
        var act_content_val = $(act_content_id).val();
        if(act_content_val !== ''){
            form_data.append(act_content, act_content_val);
        }
        var act_get = 'act_get'+i;
        var act_get_id = '-sharptextPsP5b_'+i;
        var act_get_val = $(act_get_id).val();
        if(act_get_val !== ''){
            form_data.append(act_get, act_get_val);
        }
    }`
Menu