I'm trying to extract all elements from an array but instead i'm getting the last element of it
This is my code:
// this.data contains data from a http.get
// I tried using user: [] and user: any = [];
user: Array; //
pass: Array;
for (const x of this.data) {
this.user = x.username;
this.pass = x.password;
} // console.log(this.user); Output = lastelementfromthearray
mcobject have to do with the content of the array? Anyway, apart from that, your problem is that you are overridingthis.userat every iteration, which means that you'll only get the final one at the end of the loop.datais what you want: the array of username/passwords.