I have a mixed array of values all string values. I want to take the string values representing a number and convert them to ints. Here is my array:
const data = 'new york;10.99;2000';
I split it transforming it:
const transData = data.split(';');
transData = ["new york", "10.99", "2000"]
I would like to iterate over that and return two clean int's with a string value for all non number strings. I am a bit stumped. I know this is easy to some but I have tried forEach, for, map, and I still get a NaN value for the first array member. I can't seem to filter or skip it even with an "if" check using for instance:
for(let i=0; i < transData.length; i++)
if(transData[i] != NaN){
transData[i] = + transData[i];
}else{continue};
I know how this works transData[i] = + transData[i]; I just can't seem to automate this thing with iteration/filter/map/whatever..
Any help greatly appreciated. These are baby steps into big boy/girl thinking in javascript.
Here are some of the methods I have tried:
const data = 'new york;10.99;2000';
const transData = data.split(';');
// transData[1] = + transData[1];
// transData[2] = + transData[2];
console.log(transData);
const filteredTransData = transData.filter(data => data > 0);
filteredTransData.forEach((data, idx) => {
filteredTransData[idx] = + filteredTransData[idx];