javascript: fix array operations