Having or experiencing anxiety will not cause a heart attack directly.
Although when you're experiencing anxiety you may get chest pains that may feel like you're having a heart attack but that is usually just your chest tightening up which is normal and harmless during an anxiety or panic attack.
But anxiety can eventually lead to you developing heart disease which can then lead to a heart attack eventually.
When you're suffering from anxiety and especially severe anxiety then your blood pressure can be getting too high and when that happens that leads to heart attacks, strokes, heart disease etc.
So if you're having anxiety then it would be best to get some therapy for it or get on some anxiety medications and do your best to calm down your anxiety if possible.