I thought about writing the sentence "She underwent surgery at 4 year old.", but I thought it sounded weird without seeming technically wrong, but is it? I definitively think "She underwent surgery at age 3" sounds better, but I would like to know why the former is wrong if it is.
"She underwent surgery at 4 years old." is fine, but note that "years" should be plural because we are talking about 4 of them.
We do have an idiomatic expression which is an exception to that concept (i.e. plural "years"). A "4 year old" or (hyphenated sometimes) "4-year-old" is a 3-word noun meaning a child who is 4 years old.
So you could say,
"She underwent surgery as a 4 year old."
"She underwent surgery at 4 years old."
"She underwent surgery at age 4."
All three sound equally natural to me.