jslint 'in' warning

Benchmark created by Xotic750 on


Setup

var arrayLike = {
            0: 'a',
            1: 'b',
            2: null,
            3: 'd',
            4: undefined,
            6: 'f',
            7: NaN,
            length: 8
        },
        anArrayLike = Object.create(arrayLike, {}),
        length = anArrayLike.length,
        index,
        item;

Test runner

Ready to run.

Testing in
TestOps/sec
Array.prototype.forEach
//console.log('Using Array.prototype.forEach');
// Correct: output matches the expected input
Array.prototype.forEach.call(anArrayLike, function (item, index) {
    //console.log('forEach', index, item);
});
 
ready
for, in filtered
//console.log('\nIterate based on length, in filter');
// Correct: output matches the expected input, but fails jslint because of 'in'
for (index = 0; index < length; index += 1) {
    if (index in anArrayLike) {
        item = anArrayLike[index];
        //console.log('in', item);
    }
}
ready

Revisions

You can edit these tests or add more tests to this page by appending /edit to the URL.

  • Revision 1: published by Xotic750 on