I need to get string / title from last product in my array but only after I filter all my items to get only active products, and I've tried something like this:
function getProductNoteTitle() {
if (data.product && data.product.length>0) {
var result = data.product.filter(
item => item.productStatusId === ProductStatusEnum.Active
);
result.length > 0 ? return([result.length - 1].title) : return 'Not Set';
}
}
But this wont work because I got an error on this line:
result.length > 0 ? return([result.length - 1].title) : return 'Not Set';
which says Expression expected.
returnis not keyword that forms an expression, you cannot use it as the operand of something else. You want toreturn (… ? … : …);instead - notice thereturn …;being a statement.