Postgresql Loop Through Array Javascript Duplicates On Photos