Try using var k instead of i at the second loop. Define the _someArray.length as a variable outside the loops.