After reading the string, an array of objects is created for various operations. However, upon returning the final array, I encounter a problem - the year needs to be a number instead of a string.
for (let i = 1; i < allFileLines.length; i++) {
const data = allFileLines[i].split("|");
if (data.length === newheaders.length) {
const tarry: Icface = {
title: null as string,
id: null as string,
year: null as number,
};
for (let j = 0; j < newheaders.length; j++) {
tarry[newheaders[j]] = data[j];
}
if (typeof tarry[2] === "number") {
Log.trace("number");
}
// tslint:disable-next-line:no-console
// console.log(lines);
// Log.trace(JSON.parse(JSON.stringify(tarry)));
lines.push(tarry);
}
}
The interface looks like this:
export interface Icface {
title: string;
id: string;
year: number;
[key: string]: string | number;
}
So even though the year value after processing is returned as "2018", it should actually be 2018. It's perplexing how I'm able to work with the string representation of the year using operators like "<" and "===". Any ideas?