fix for loop caused by extending javascript Array