Jesus knew from the beginning that one of His disciples would betray Him:
John 6:64, 70-71
But there are some of you who do not believe.” For Jesus knew from the beginning who they were who did not believe, and who it was that would betray Him. ... 70 Jesus answered them, “Did I Myself not choose you, the twelve, and yet one of you is a devil?” 71 Now He meant Judas the son of Simon Iscariot, for he, one of the twelve, was going to betray Him.
John 13:11
For He knew the one who was betraying Him; for this reason He said, “Not all of you are clean.”
John 13:18
I do not speak of all of you. I know the ones I have chosen; but it is that the Scripture may be fulfilled, ‘He who eats My bread has lifted up his heel against Me.’
John 17:12
“While I was with them in the world, I kept them in Your name. Those whom You gave Me I have kept; and none of them is lost except the son of perdition, that the Scripture might be fulfilled.