There are two matters here.
Jesus was a prophet as predicted in Deut 18:15, 18-20 and documented as fulfilled in Acts 3:21-23. This is confirmed numerous times in other places such as: Matt 13:57, 21:11, 46, Mark 6:4, Luke 4:24, 24:19, John 4:44, 6:14, etc. This is NOT to suggest that Jesus was merely a prophet, He was the divine Son of God, but during His incarnation as Messiah, he was, among other things, a prophet.
The prophets were given access to divine information that enabled them to understand things beyond the reach or human knowledge and wisdom. This enabled the prophets to do remarkable things such as write the prophecies of Messiah and the future (2 Peter 1:19-21), etc. Such divine knowledge permitted the ancient prophets to know things about the king; eg, Elisha telling his king about what the enemies were doing, 2 Kings 6:8-23.
Thus, it is immediately clear that if Jesus were Messiah and a prophet, Jesus had access to divine knowledge via the enlightenment of the Holy Spirit to do some remarkable things.
That is, Jesus knowledge about the woman's past (John 4:18) does not necessarily suggest omniscience of Jesus. It simply confirms what the woman said next (V19), "Sir, I perceive that you are a prophet!"
APPENDIX - Logical possibilities
The above analysis does not necessarily preclude the possibility that Jesus was omniscient. [Here, I should declare my bias and say that I believe Jesus was omniscient, as well as omnipotent and omnipresent, etc.] However, as explained in the previous question here >> Did the disciples believe that Jesus was omniscient? , during Jesus' incarnations, these privileges were voluntarily put aside (Phil 2:5-8) so that Jesus depended only on the same power and authority that any other person has.
However - If Jesus used His innate omniscience to know all the things only known to divine knowledge, then He would NOT have been a prophet during the incarnation. That is, the very fact that Jesus was called a prophet means that He used the the Holy Spirit as the source of divine knowledge rather than His own.