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

Number() method doesn't give me proper output

I’m creating a React project which includes images.
In my project I want to get the width and height of image that uploaded.
For that I am using

const image = document.getElementById("inputimage");
const width = Number (image.width);
const height = Number (image.height);
console.log( width, height );

Image tag in another page

<img id='inputimage' alt='image' src={imageUrl} width="500px" height="auto" />

Here Number() is used to convert the image.width and image.height into numbers for future calculations.
Whenever I run this code I didn’t get the output.

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

const image = document.getElementById("inputimage");
const width = image.width;
const height = image.height;
console.log( width, height );

But when I remove the Number() then I got output.

Does anyone know why I didn’t get output when Number() is used ?
There is anything I can do for converting the image.width and image.height into numbers?

>Solution :

I think you can use parseInt(image.width) (or image.height).

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