How can new object push into array ionic new


#1

how can new object push into array ionic 2 new


#2
myArray.push(new MyObject());

#3

sir,
this myarray=[ ] is where is declared …


#4

i am declraring array in here so this refresh page load

public items:[];

constructor(private navCtrl: NavController) {

}

this.array={
name: this.name
}

this.items.push(this.array);


#5

This is not a proper declaration, and should be initialized as = [].

In addition to floating in the middle of nowhere and not actually being declared as an object property, this is very poorly named on two fronts: “array” is not a very descriptive name, and this is not an array.

Again we float in the ether, so I have no idea where this is actually being invoked from, but at the time that it is, this.items must actually be an array. See my first comment about initialization.


#6

sir,
can you show me 1 simple example


#7

MDN.


#8

sir,
i am just reffer this link but sir its not properly work in ionic 2 …

my page on page enter time all pushing array is cleaned how can i stop him.


#9

i think declaring array problem


#10

What if I am pushing an object into an array of objects?