0

Through an input field, I am collecting values separated by commas like this "10", "20", "30" which come as an array in my req. body.

Like this req. body.options= ["10","20","30"].

I want to store each value as an array value like this

option[0] = 10,
option[1] = 20,
option[3] = 30,

but now when I store value like this

options = req.body.options.

I get results like this

option[0] =["10","20","30"].

Quite new to programming. So appreciate any sort of help.

Newbie_developer
  • 233
  • 1
  • 12
  • https://stackoverflow.com/questions/4437916/how-to-convert-all-elements-in-an-array-to-integer-in-javascript this? sorry I do not have comment privileges yet – ritvik seth Jul 29 '22 at 19:48

1 Answers1

0

Simply do it, using the spread operator:

let options = [...req.body.options];

Here's the link to documentation.

Charchit Kapoor
  • 8,934
  • 2
  • 8
  • 24