javascript: fix wrong array handling