Hi Leute,
Ich hab ein Problem undzwar soll ich in einem Array mit mehren Objekten welche herausfiltern. Als string mit endsWith() klappt das auch ganz gut. Es sollen aber auch die Objekte gefilter werden die nur ein / im Path haben und somit dann in ein neues Array geschrieben werden. Da dachte ich an folgende Lösung. Aufgabe ist also zuerst nach .config zu filtern und dann nach einer datei die nur ein / hat oder anderst rum das ist eigentlich egal.
hier mal der ganze Code;
let items = [
{
fileName: 'test.zip',
path: 'HPCWebAccessService/Test/test.zip',
},
{
fileName: 'test.doc',
path: 'HPCWebAccessService/Test/test.doc',
},
{
fileName: 'test1.config',
path: 'HPCWebAccessService/test1.config',
},
{
fileName: 'test2.config',
path: 'HPCWebAccessService/Test/test2.config',
}
];
// Result we want to get
let resultToGet = [
{
fileName: 'test1.config',
path: 'HPCWebAccessService/test1.config',
}
];
function selectConfg(item)
{
var element= '.config';
return item.fileName.endsWith(element);
}
function selectSlash(item)
{
let count=0;
let name= resultt.path.toString();
let pos = name.indexOf('/');
console.log('hallo');
while(pos!=-1){
console.log('hallo2');
count++;
console.log(count);
}
if(count==1){
console.log('Hallo3');
console.log(count);
return true;
}else if(count >1){
console.log('Hallo4');
return false;
}
}
let resultt = items.filter(selectConfg);
let result= resultt.filter(selectSlash);
//TODO: Filter array
console.log(result);
Fehler im Compilier
TypeError: Cannot read property 'toString' of undefined at selectSlash:36:27 at Array.filter at eval:54:22 at eval
Danke für eure Hilfe im Vorrraus