0

I have searched and found ways to check for ALL whitespace existence between letters in a string but what about if the string contains a space, tab or enter at the end?

For example:

let str="John ";
console.log(str.includes(' '));

The above console.log will return true because there is a space at the end, however that is not relevant for me. I only wanted to check for:

let str="J o h n";

How to achieve this with Javascript ( and totally ignore space check at the end)?

RandomDeveloper
  • 833
  • 2
  • 9
  • 31

1 Answers1

0

If I understand your question correctly, this is what you want to achieve:

let str="John ";
console.log(/\s$/.test(str));

Virhile
  • 88
  • 8