editing $data

So I just started to learn how to make plugins. Here's the situation:
In the editor, I made the class #1 have notetag...
<Fruits>
Banana
Orange
Apple
Apple
Grapes
</Fruits>

I want to add another Banana in the list later in the game by an event. so I created an event that run a script something like...
$dataClasses[1].fruits.push("Banana");

It did add "Banana" in the list of fruits but the problem is, after saving the progress and restarting the game, the changes are gone as if it didn't save the new list of fruits which should now include another Banana. In other words, it's back to the original data. So how can I properly add Banana permanently in the middle of the game?
It won't work, for exactly the reason you said.

$data... objects are not saved with your save file. They are read when the game first loads and not again until you close and reload.

This means you can make changes, save your game, exit, load and continue, and your changes will be gone.
It also means you can make changes, save your game, go back to the menu and start a new game, and your changes will be present in the new game.

If you want something that gets saved in the player's save file, stay away from the $data objects. Instead, put it into a new property of $gameSystem or $gamePlayer or something like that. This means you will have to create it via script and not note tags, or your plugin will have to read it from note tags and save it to one of the $game... objects every time New Game is chosen.
uhm... If I understood that right, it is impossible to modify/add a new data to a class mid game?
exactly - what most people do is redirect the data elsewhere if they want to modify it. You can check several plugins for dynamic effects and how they do it.
Only the editor should write the files with the $data content.
If I understood that right, it is impossible to modify/add a new data to a class mid game?
That's not what I said. I said you can't change the $data... objects because they are not a part of the data that's saved when the player saves their game. It is refreshed when a new game is started, and only when a new game is started.

If you only wanted to set up extra stuff on a class and not change it during the game, it's fine to set it up via note tags. But if you want to change it, as you do, do not put it in the $data... objects. Put it somewhere else - in an object that IS saved when the player saves their game, such as the objects I already listed.

Original thread: https://forums.rpgmakerweb.com/threads/editing-data.115634/