@Allen Yes your code could be vastly improved. If you send me your project I will make a video for my YouTube channel going through some of the things I think could help to make your code more manageable.
Here are some general tips.
Never use var unless you have no other choice.
Objects and arrays should generally be declared as const (or local within inline functions).
All those reg variables you have could be replaced with a single const - look up JSON.