I am looking to create a JavaScript object in the following format:
var CarList = {};
I then want to populate it using a for loop (retrieving data from a MySQL database) similar to this:
for(var i = 0; i < result.length; i++)
{
CarList.Constructeur = result[i].Constructeur;
CarList.Modele = result[i].Modele;
CarList.Couleur = result[i].Couleur;
CarList.Immat = result[i].Immat;
CarList.VIN = result[i].VIN;
CarList.DMC = result[i].Date_Mise_en_circulation;
CarList.Enregistrement = result[i].Date_enregistrement;
}
The issue I am facing is that only the last car in the database is being displayed. I believe I am missing an [i] somewhere in my code, as it is only creating one car child instead of multiple as per my database.
What is the correct way to address this issue?
I have already attempted using CarList[i], CarList.[i].*, and CarList.car[i].*