Javascript Loop Through Array Of Objects And Function