-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']
1
  • Those "non-strings" look like numbers. If your intension is to convert string to number there are several ways to do so. Commented Nov 28, 2022 at 10:23

1 Answer 1

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);

Sign up to request clarification or add additional context in comments.

2 Comments

You could just do .map(Number), instead.
Yeah but I like it this way arr.map(i => Number(i)). As it explains what's going on.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.