Chrome Extension

Get first 10 words from string javascript

function getWordStr(str) {
    return str.split(/\s+/).slice(0,10).join(" ");
}

//TO CALL THIS FUNCTION
var fullStr = "We can get first 10 words form this string using the above function";
var finalStr = getWordStr(fullStr);

console.log(finalStr);
We are a bunch of lazy programmers so we developed this chrome extension
search code from your favorite search engine
Install Now
Output
We can get first 10 words form this string using

The code snippet can be used to get first 10 words from a string. You can set start and end points in the 'getWordStr' function. We have applied a start point form 0 and end point to 10. 

Search Index Data (The code snippet can also be found with below search text)

Get n words string from another string javascript
Was this helpful?
0 Comments
Open Code Manager We are hiring