Search code examples
javascriptjqueryjslint

JSLint message: Unused variables


what can I do if JSLint complains about "i" being an unused variable in such a scenario:

var items = "<option selected></option>";
$.each(data, function (i, item) {
    items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
});

(i, item) is the required order of parameters and I'm only using "item".

Is there any other solution than tolerating unused variables or rewriting the $.each to use the index, both solutions which I would prefer not to do?

Thanks in advance.

Update: I appreciate all the suggestions but this code is simply an example to show you what I mean and I'm interested to see a general solution, if there's any. Thanks.


Solution

  • Try:

    var items = "<option selected></option>";
    /*jslint unparam: true*/
    $.each(data, function (i, item) {
        items += "<option value='" + item.Value + "'>" + item.Text + "</option>";
    });
    /*jslint unparam: false*/  // so that you still get warnings from other functions