Jelena M.
Jelena M.

Reputation: 15

Typescript array push new objects

This is my code:

this.restarray.forEach(element => {                     
    element.forEach(elt => {
        let restallx = {name: elt.name, xval: elt.value};
        this.restall.push(restallx);            
        console.log(elt.name);
        console.log(this.restall);
    });
});

When I print elt.name I get multiple name's, but when i print this.restall I get only last name and value. Anyone have idea what's wrong with my code?

Upvotes: 0

Views: 2928

Answers (1)

Santosh Jadi
Santosh Jadi

Reputation: 1525

Declare restall: Array[] = []; globally.

Upvotes: 2

Related Questions