javascript.....
The includes function is not behaving as it is supposed to......
enum EInspectionStage {
rejected = "Rejected"
}
nextStagesList
?.filter(({ title }) => {
console.log(
EInspectionStage.rejected.toLowerCase().trim(),
title?.toLowerCase()?.trim(),
EInspectionStage.rejected
.toLowerCase()
?.trim()
?.includes(String(title?.toLowerCase()?.trim()))
)
return !EInspectionStage.rejected.toLowerCase()?.includes(title?.toLowerCase())
}
So the console logs out this output for the case where title is "reject"
rejected reject false
However is i try to log -> "rejected".includes("reject") // true
nextStagesList.filter(({title}) = > { const t = title?.trim()?.toLowerCase(); if(!t) return false; const stage = EInspectionStage.reject.toLowerCase(); console.log({stage, t, result: stage.includes(t)}) return stage.includes(t); })
I did not get into all the logic, but it seems to me, you shouldn't use the question mark after Trim. It always returns a string.
UPDATE! Thanks for the solution guys.... The issue is resolved.... The problem was that the title had some 0 character hidden white space in it, as it was coming from the backend through rest API.....
Обсуждают сегодня