It's worth noting that κόσμος, or "world" in John 18:36-37, refers to the order or arrangement of society, rather than the whole world as we know it today. There were 3 different Greek words that were translated as "world". https://christogenea.org/articles/what-world