Postgresql Loop Through Array Javascript Duplicates In Photos