I can not get around JSHint's error message. Here is the loop I am using:
for (i = 0; i < Collection.length; i += 4) {
data.push({
items : Collection.slice(i, i + 4).map(function(item) {
return {
id: item[0],
title: item[1],
};
})
});
}
You can just move the function outside the loop and pass a reference to it to
map
:Alternatively, you can use a JSHint directive to ignore function expressions inside loops. Just put this at the top of the file in question:
Declaring a function in a loop is messy, and potentially error prone. Instead, define the function once, and then enter the loop.