God is loving, but God's love requires God's justice. Many people struggle with this. Now, how could a loving God command the destruction of all those "innocent" people? The argument sounds good, but it isn't. The unstated assumption is that the people who God ordered destroyed were morally equivalent to the Jews, who replaced them. Deuteronomy 9:5 and Deuteronomy 12:31 talks about the "wicked" people.
How "wicked" could those people have been? Well, how about killing their own sons and daughters by burning them in sacrifices to their gods. These people are not quite as innocent as some atheists would like you to believe.
This was the exception to the rule. God killed for the least or greatest offense, with prejudice. Starting at Numbers 16:30, you will read how God killed folks for . "wicked" people as you might say. The Isrealites are scared because of the spectacle, and complain about how Moses had played a part in the execution. So, God killed 14,700 Isrealites by plague for complaining. It was really a heartless act, as these people were confused, scared, and sad. It is perfectly normal for a person to feel anger towards the judge who puts their guilty son in the chair. God had no mercy in this case.