动态设置json选择器

I have an array with an unknown amount of values in the structure of ['someNumber0', 'someNumber1',..]. These numbers need to be passed into my ajax call as data query strings. The catch is I need to name each number first.

I am attempting a hack but it is not working as I cannot set the json selector(?) dynamically.

var zipArray = $("#enteredValue").val().split(',');
    var dataObj = {};
    var i = 0;

    zipArray.forEach(function (value) {
        var queryString = "zip" + i;
        ++i;
        dataObj = { queryString: value }; //does not pass the var (querystring)
    });
    console.log(dataObj)

    $.ajax({
        type: 'GET',
        url: "http://localhost:49528/Proxy.aspx",
        data: dataObj,
        dataType: 'json',
        success: function (json_results) {
            SucceededCallback(json_results);
        }
    });

Suggestions?

You've been overwriting dataObj each time in your loop you did:

dataObj = { queryString: value }; // overwrites dataObj

Instead do this:

dataObj[queryString] = value; // adds a new property to dataObj or modifies existing property

That must be the root of your problem.