I am new to jquery and stuck in a problem and need help from experts.
here is my code
for (val in list) {
var result = $.grep(node, function(e){
return e.id === list[val].Id;
});
if (result === 0)
// do something
}
When i try to pass JSLint on my I got this error
#1 Don't make functions within a loop.
I know the problem that i am making a function in the jquery grep function But i am stuck as how to move my function out side the loop assign it to a variable and then call it. As my function is talking an argument e. I have tried it like this
var Visible = function (e, list, val) {return e.id === list[val].Id;};
for (val in list) {
var result = $.grep(node, Visible(e, list, val));
}
but now jslint is giving an error that
#1 'e' was used before it was defined.
var result = $.grep(node, Visible(e)); // Line 125, Pos 69
//--------------------------------------------------------------------
here is the data
node: Array[5]
0: HTMLTableRowElement
1: HTMLTableRowElement
2: HTMLTableRowElement
3: HTMLTableRowElement
list: Array[5]
0: Object
0: "cc"
1: "ss"
Id: "000"
1: Object
2: Object
Now I am finding that for which element of the the list an html element exist. If for any element in the list and htmlelement does not exist then i r=create one i am checking it by result === 0 what can be the solution to this problem. Any help will be appreciated thanks