One way to prevent muscle cramps is to get enough of these nutrients: potassium, sodium, calcium, and magnesium. They’re called electrolytes, and this WebMD slideshow can help you find them in these foods.