javascript find first element in array that matches