Postgresql Index Array Javascript Function