Search code examples
javascriptstringreactjsreduxparseint

ParseInt() doesn't return ending zero


I'm in a React project and I'm trying to convert a string to an Integer.

pageSize: '30'

But when I convert it with

var convertNumber = parseInt(...this.props.actionData.pageSize, 10)

The console log give me:

3 0

There's whitespace inside the number. How do I remove the space or solve the problem?

Thanks


Solution

  • If pageSize is the string "30", the action of ... will be to split it to it's chars, so you actually get ["3", "0"]. If you will run parseInt on each of these, you will get 3 0.

    Why do you spread the string to it's chars instead of just use parseInt on that string?