I've seen posts where you use a variation of .push() .push(undefined) and .push(null) but none seem to work.. my issue might be that when I am joining the list into a string, it gets rid of the empty ones.
The ultimate goal is to iterate through an array of arrays, then for each item in a "row", remove commas from the item if it is a string, and has a comma. My code is messy, I apologize.
Due to a lot of comments I shortened the code as much as I could.. I wanted to include my .join() because I think that might be part of my issue, thanks.
let someRow = [6, "Gaston,OH", "Brumm", "Male", , , , 2554];
function remCommas(row) {
let newRow = [];
for (let item in row) {
if (typeof row[item] === "string") {
let Str = row[item].split();
console.log(Str);
let newStr = [];
for (let char in Str) {
if (Str[char] !== ",") {
newStr.push(Str[char]);
}
}
newRow.push(newStr.join());
} else {
newRow.push(row[item]);
}
}
console.log(newRow);
return newRow;
}
remCommas(someRow);
// input: [6, "Gaston, OH", "Brumm", "Male", , , , 2554]
//expected output: [6, "Gaston OH", "Brumm", "Male", , , , 2554]
// current ouput: [6, "Gaston, OH", "Brumm", "Male", 2554]