0

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?

5
  • Declare restall gobally Commented Apr 14, 2018 at 15:43
  • what's stored in restarray? Commented Apr 14, 2018 at 15:45
  • @SantoshJadi, it is declared globally. e.g.: public restall:Array<any>=[]; Commented Apr 14, 2018 at 15:47
  • Try to declare it like restall: Array[] = []; Hope it works Commented Apr 14, 2018 at 15:53
  • @santoshjadi, it work's, thank you. Commented Apr 14, 2018 at 16:16

1 Answer 1

2

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

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.