Could someone lend a hand in getting this to function...
The code snippet below is functioning
const acco = [{FullyQualifiedName=(-) Imposto Unico, Id=109, sparse=true, AcctNum=3.1.2.01.03027}, {FullyQualifiedName=13º Salário, Id=114, sparse=true, AcctNum=4.1.2.04.04062}, {Id=94, AcctNum=2.1.3.01.02183, FullyQualifiedName=13º Salário a Pagar, sparse=true}, {Id=90, FullyQualifiedName=Adiantamento de Férias, sparse=true}
var payacc = '2.1.3.01.02183';
var accDC = acco.filter(obj => obj.AcctNum === payacc);
if (accDC.length != 0) {
var accvalid = accDC[0].AcctNum + ' ' + accDC[0].FullyQualifiedName;
}
//accvalid = 2.1.3.01.02183 13º Salário a Pagar
However, the following code snippet gives an undefined result
const acco = [{FullyQualifiedName=(-) Imposto Unico, Id=109, sparse=true, AcctNum=3.1.2.01.03027}, {FullyQualifiedName=13º Salário, Id=114, sparse=true, AcctNum=4.1.2.04.04062}, {Id=94, AcctNum=2.1.3.01.02183, FullyQualifiedName=13º Salário a Pagar, sparse=true}, {Id=90, FullyQualifiedName=Adiantamento de Férias, sparse=true}
var payacc = '02183';
var accDC = acco.filter(obj => obj.AcctNum.includes(payacc));
if (accDC.length != 0) {
var accvalid = accDC[0].AcctNum + ' ' + accDC[0].FullyQualifiedName;
}
returns TypeError: Cannot read property 'includes' of undefined
I suspect this occurs because there is no AcctNum for the last entry, but how can I bypass this? Apologies if I'm overlooking something too obvious.