0

is there any way in angular 2 (v. 2.4.0) to make for loop, or forEach loop taking every objects from class? I mean

export interface RegistrationDataInterface {
first_name: string;
    surname: string;
    used_name: string;
    email: string;
}
export class Smth{
registrationSharingData: RegistrationDataInterface;
 checkOut(){
forEach(item from this.registrationSharingData)
{
    if(item!="null")
    {//dosmth}
}}}

I dont want to make 20 ifs, thanks :)

Jędrek Markowski
  • 444
  • 3
  • 6
  • 25

1 Answers1

3

You can do this,

for (let item of this.registrationSharingData){

}

since you want to check inside the Object, you don't need a loop,

checkOut(){
   You can just access the properties like this.registrationSharingData.whateverfield
}
Sajeetharan
  • 216,225
  • 63
  • 350
  • 396