So after creating an object,I want to add it to an array but seem it doesn't working Only the last one was added and it looped.
I expect the output of mang[0]
would be ('Samsung S8','s0','$200')
but it doesn't.
It only show the last one ('Samsung A60','s2','$400')
. It's the same to mang[1]
.
var mang=[];
var Phone = {
Name:'',
Img:'',
Price:'',
them :function(name,img,price){
this.Name=name;
this.Img=img;
this.Price=price;
mang.push(Phone);
}
};
Phone.them('Samsung S8','s0','$200');
Phone.them('Samsung S10','s1','$300');
Phone.them('Samsung A60','s2','$400');