Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 579
TheFitGeekGirl Avatar asked Jul 05 '11 13:07

TheFitGeekGirl


1 Answers

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 
like image 118
nickf Avatar answered Sep 29 '22 16:09

nickf