I have an array containing two strings: '1' and '5' for example. I want to save those two strings into parameters, but already as integer numbers. Currently, the code looks like this:
const data = ['1', '5']; const [min_str, max_str] = data; const min = parseInt(min_str, 10); const max = parseInt(max_str, 10); console.log(typeof min_str, typeof max_str, typeof min, typeof max)
Maybe you can use map()
map()
const [min_str, max_str] = data.map(x => parseInt(x, 10));
If the strings are only numbers inside strings. You can also use Number
Number
const [min_str, max_str] = data.map(Number);
1.4m articles
1.4m replys
5 comments
56.9k users