-1

I read-in elements from an HTML DOM input and save them into an array. Unfortunately, my code creates an array of strings as illustrated in the code below:

let delete00To04Am = document.getElementById("time000am400amEveryDay").value.split(',');

console.log(delete00To04Am);

The code above yields:

['1669669200000', '1669755600000']

It is NOT my intention to for the elements to be saved as strings in the array. How do I convert the contents of the array from strings into non-strings

For clarity purposes, my desired result is:

console.log(delete00To04Am);

[1669669200000, 1669755600000]

and NOT:

['1669669200000', '1669755600000']
SirBT
  • 1,580
  • 5
  • 22
  • 51
  • Those *"non-strings"* look like numbers. If your intension is to convert string to number there are [several ways](https://dev.to/sanchithasr/7-ways-to-convert-a-string-to-number-in-javascript-4l) to do so. – zer00ne Nov 28 '22 at 10:23

1 Answers1

1

Use map to iterate over each element and convert it to a number using Number

const arr = ['1669669200000', '1669755600000'];
const numArr = arr.map(i => Number(i));
console.log(numArr);
Nishant
  • 466
  • 2
  • 15