How can I do this in Javascript?