Te issue with borrowing from most 401ks is the interest you’re paying back may not match what the market would have paid and most plans won’t allow you to contribute until its paid back.
I have a friend who back in the 80s lost his job & he had to cash out to support his family. He’s still working and he’s 70. Every dollar you invest in your 20s is worth $85 around the time you retire.
The reason borrowing from the 401k worked for me was that when I was borrowing the amount was relatively small (just enough for a down payment) and I was able to pay it back in just a couple of years.
My income got a lot higher after that so I was able to quickly crank a lot of cash into the 401K for several more decades and did just fine.
Meanwhile we got the house we wanted (which we still live in btw).