You can use `$.each` instead of while loop.