Welcome!

By registering with us, you'll be able to discuss, share and private message with other members of our community.

SignUp Now!
  • Guest, before posting your code please take these rules into consideration:
    • It is required to use our BBCode feature to display your code. While within the editor click < / > or >_ and place your code within the BB Code prompt. This helps others with finding a solution by making it easier to read and easier to copy.
    • You can also use markdown to share your code. When using markdown your code will be automatically converted to BBCode. For help with markdown check out the markdown guide.
    • Don't share a wall of code. All we want is the problem area, the code related to your issue.


    To learn more about how to use our BBCode feature, please click here.

    Thank you, Code Forum.

JavaScript Having problems with NaN in datasets

Milton

New Coder
Hi All,

First post here.

I am having problems with NaN in Table Data in datasets in javascript.

I have a database that has been created in Filemaker, which is then converted to excel and then pasted into the table for my web page.
All the data including any empty cells display correctly in my datatable.

Any data that I have extracted to constants shows up correctly, but any data extracted that has empty cells returns NaN in the datasets for a chart.

Is there a way to not include empty cells in the dataset?

There are 3 datasets, each with 44 TD's for each table row.

As an example, the following is a constant that shows up correctly in a paragraph.

Code:
const gamesThisYear = cells[1].innerText;

And the constant that returns a correct value if there is a number in it, but NaN if it is empty is:

Code:
const WK1_TH = parseFloat(cells[13].innerText);

Any assistaance wold be extremely helpful.

Regards

Milton.
 
Hi there, the reason why it's returning NaN (meaning not a number) is because you're trying to convert a non-existent or empty value (undefined or null) into a floating-point number, and well, the result isn't a number.
1728028641624.png

Is there a way to not include empty cells in the dataset?
To completely filter out any empty cells, you could use the Array.filter() method to filter out any null values:
JavaScript:
const filteredCells = cells.filter((cell) => cell.innerText != null);
 

New Threads

Buy us a coffee!

Back
Top Bottom