here i need the find the file extension among the given file names i.e i have 2 variable one is fileData which contains the file extensions and filename which contains the filename so here we have to check the whether the filenames having that particular extension or not if it is having then we have to retrieve the filename extension
fileData = ['exe', 'obj', 'file', 'data'];
filename = ['one.exe', 'two.obj', 'three.p', null, undefined];
constructor() {
var fileSplit;
for (var i of this.filename) {
fileSplit = i.substring(i.lastIndexOf('.') + 1, i.length) || i;
if (this.fileData.includes(fileSplit)) {
console.log('File name::', i, 'and file extension::', fileSplit);
} else {
console.log('File name not there::', i)
}
}
}
GETTING THIS ERROR : ERROR
Error: Cannot read property 'substring' of null
stackblitz link https://stackblitz.com/edit/angular-ott3vh