take n values from a javascript iterator