Javascript Array Group By Function In Sql