That all depends on your 401(k) Plan Document. If the Plan Document states that loans are allowed you would apply for the loan. As long as you meet all of the requirements (minimum balance, minimum loan amount, etc.) you will be able to receive the loan. I would advise you that when you take a loan, while it is better than a hardship, loans have consequences.
Loan money is double taxed. You will be repaying the money with after tax dollars, thus resulting in a double taxation because you will either pay taxes when you pull the money out in retirement or you will have already paid taxes on the money if it was from a Roth 401(k).
Depending on the Plan Document, if you are terminated with a loan outstanding that can be added to your income and treated as an early distribution causing a 10% penalty if you are younger than 59 1/2.
Depending on the Plan Document, you may or may not be able to continue to make contributions on top of your loan repayment.
There is also the loss of the time value of that money while it is not invested you are missing out on potential profits, but you could also take it out at the right time and be rewarded for missing out on potential losses.
Those are a couple things to keep in mind. Again, the loan is better than a hardship distribution, but may not make the most sense if you have other means.