Ad
NaN When Trying To Multiply A Json Value With Local Variable
i'm trying to change a JSON value from an object from seconds to hours. The problem is, when I try to multiply it with my local constant to convert it, it returns a NaN value.
i've already tried using JSON.stringify(Json_value) and it didn't help
const secToHours = '0,000277778';
const hourTime = secToHours*JSON.stringify(jsonData.duration);
logs = []
logs.push({"id":jsonData.id,"key":jsonData.issueKey, "date": dateFormatted, "duration": hourTime})
var array = [{user:jsonData.userId, logs:logs}];
console.log(array[0]);
This is the console output:
{
user: 'XXXXX',
logs: [ { id: XXXXX, key: 'XX-X', date: '2019-7-3', duration: NaN } ]
}
I don't know why it's returning a NaN value for the multiplication, and if i print the values separated, they return the respective const value and the json data.
Ad
Answer
0,000277778
is not a valid JS number - your local convention may use comma's as a decimal point, but JS expects a dot.
You don't need/want to use JSON.stringify
on jsonData.duration
though I can't see from this if you need to manipulate it in some other way - where is it declared/what value does it have on line 2?
Ad
source: stackoverflow.com
Related Questions
- → How to update data attribute on Ajax complete
- → October CMS - Radio Button Ajax Click Twice in a Row Causes Content to disappear
- → Octobercms Component Unique id (Twig & Javascript)
- → Passing a JS var from AJAX response to Twig
- → Laravel {!! Form::open() !!} doesn't work within AngularJS
- → DropzoneJS & Laravel - Output form validation errors
- → Import statement and Babel
- → Uncaught TypeError: Cannot read property '__SECRET_DOM_DO_NOT_USE_OR_YOU_WILL_BE_FIRED' of undefined
- → React-router: Passing props to children
- → ListView.DataSource looping data for React Native
- → Can't test submit handler in React component
- → React + Flux - How to avoid global variable
- → Webpack, React & Babel, not rendering DOM
Ad