Javascript Array Count With Condition In Sql