Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Why is parseInt displaying Nan? – Angular

I am currently iterating through an array and adding the key to my panels array. I am getting the correct length of the array which is three but my parseint is displaying NaN. How can I convert the key which is a string to an int to display panel-0 for example instead of panel-NaN.

Object.keys(this.Category).forEach((key) => {
      this.panels.push(parseInt(key, 3));
      this.activeIds = this.panels.map(p => 'panel-' + p);
    });```

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

what you are doing is parseInt('Car' 3), since "Car" is not a number you will get NaN

probaby you want something like this:

Object.keys(this.Category).forEach((key) => {
   this.panels.push('panel-' + panels.length + 1);
});
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading