Answer the question
In order to leave comments, you need to log in
How to get first 2 words from input?
I am new to jquery. I'm interested in how you can get the first 2 words from the input? (words can be separated by spaces or "-")
Answer the question
In order to leave comments, you need to log in
"some random string".split(/[\s\-]/).slice(0, 2); // ["some", "random"]
"some-random string".split(/[\s\-]/).slice(0, 2); // ["some", "random"]
"some random-string".split(/[\s\-]/).slice(0, 2); // ["some", "random"]
"some-random-string".split(/[\s\-]/).slice(0, 2); // ["some", "random"]
arr = "a,b,c".split(',') // массив ["a", "b", "c"]
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question