Get started with underscore.string CDN

MIT licensed

Utility library: Underscore.string offers string interpolation, repeats, and joins for JS.

Tags:
  • utility
  • string
  • underscore

Stable version

Copied!

How to start using underscore.string CDN


// Include underscore.string library
const _ = window._;

// Use the library to perform string manipulations
const str = 'Hello World!';

// Repeat a string a given number of times
const repeatedStr = _.repeat('Hello ', 3); // 'Hello Hello Hello Hello'

// Replace all occurrences of a substring with another substring
const replacedStr = _.replace(str, 'World', 'Universe'); // 'Hello Universe!'

// Split a string into an array using a custom separator
const splitStr = _.split(str, ' '); // ['Hello', 'World']

// Join an array of strings into a single string using a custom separator
const joinedStr = _.join(splitStr, '-'); // 'Hello-World'

// Capitalize the first letter of each word in a string
const capitalizedStr = _.map(splitStr, (word) => _.capitalize(word)); // ['Hello' => 'Hello', 'World' => 'World'] => ['Hello', 'World']
const capitalizedAndJoinedStr = _.join(capitalizedStr, ' '); // 'Hello World'
Copied!
Copied!

All versions