Postgresql Index Array Javascript Iteration