Communities for your favorite technologies. Explore all Collectives
Stack Overflow for Teams is now called Stack Internal. Bring the best of human thought and AI automation together at your work.
Bring the best of human thought and AI automation together at your work. Learn more
Find centralized, trusted content and collaborate around the technologies you use most.
Stack Internal
Knowledge at work
Bring the best of human thought and AI automation together at your work.
I want to check to see if an item in an array/list of strings has 1 or more spaces and/or 1 or more line breaks.
What exactly would I check for in an if statement, if I wanted to check to see if the string item has this?
if
[javascript] string contains space
if (/\s*/.test("hello\n")) { alert("foo"); }
Possibly:
count = string.search(/\s/);
Where string is your input, \s is the regex for space characters, and count is the total number found in string.
Further info here:
javascript regex to count whitespace characters
Add a comment
Required, but never shown
By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.
Start asking to get answers
Find the answer to your question by asking.
Explore related questions
See similar questions with these tags.
[javascript] string contains spaceif (/\s*/.test("hello\n")) { alert("foo"); }