Postgres Function Array Javascript Iteration