aws-appsync-community
aws-appsync-community copied to clipboard
APPSYNC_JS support for parseInt, parseFloat and Number()
I tried to convert my object keys from string to numbers, but got "The code contains one or more errors. " as a response when I tried to use parseInt
, parseFloat
or Number()
.
+1
myReturnObject = {}
stringFromPreviousResult = "52.525243"
myReturnObject.property = Number(stringFromPreviousResult)
What is the proper way to convert a string to a number with APPSYNC_JS runtime?
As a workaround I used the unary operator: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Unary_plus
const test = '123';
const testNumber = +test;