How to Print the Alphabet in Typescript?

We are trying to design a health care app using Angular. For data filtering we are creating a bar which looks like this below image:

Data Filterbar image

To reduce the line of code we are writing the code in Typescript we are checking in the console whether its displaying or not.

We are not getting the expected output nor is it showing errors.

Can anyone fix this issue?

listIndex(){
while (this.i <= 90) {
    this.alphabets.push(String.fromCharCode(this.i));
}
console.log(this.alphabets());}

Output:

A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

For your reference I'm posting the full TS file:

import {Component} from '@angular/core';
import {HttpService} from '../../service/http.service';


@Component({
    selector: 'patienthtml',
    templateUrl: 'app/component/patient/patient.html',
    providers: [HttpService]
})

export class PatientComponent{
constructor( private httpService: HttpService ) {
}
 //simple call init function on controller
i=65;
step = 0;

patientData : any;
alphabets: any = [];

public ngOnInit(): any
{
    this.getPatientData();
}
 getPatientData(){

    this.httpService.getPatients("PatientData").subscribe(
    resp => {    
        if(resp!=null){

            this.patientData=resp.response;
        }
        console.log(this.patientData);
    },
    error => {
        console.log(error);
    }
    );   
}
listIndex(){
    console.log('ReachedHere');
    let alphabets = [];
    for (let i = 65; i <= 90;i++) {
        alphabets.push(String.fromCharCode(this.i));
    }
    console.log(alphabets);

}
getCurrentStep() {
    return this.step;
}
goback(){
    this.step = this.step - 1;    }

toReport(){
    this.step = this.step + 1;    }

}
6

1 Answer

Hope this helps...

let alphabets = [];
for (let i = 65; i <= 90;i++) {
    alphabets.push(String.fromCharCode(i));
}
console.log(alphabets);
3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Elena Rostova

Elena Rostova

Lead Health, Wellness & Medical Journalist

Elena Rostova holds a Master's degree in Public Health Journalism. She covers groundbreaking medical research, holistic wellness trends, mental health awareness, and nutritional science.

Share this article
Twitter Facebook Pinterest