String Manipulation with Lodash
Lodash offers various functions for working with strings. Here are some frequently used string manipulation methods:
Converts string
to camel case.
_.camelCase('Foo Bar');
// => 'fooBar'
_.camelCase('--foo-bar--');
// => 'fooBar'
_.camelCase('__FOO_BAR__');
// => 'fooBar'
Removes leading and trailing whitespace or specified characters from string
.
_.trim(' abc ');
// => 'abc'
_.trim('-_-abc-_-', '_-');
// => 'abc'
Creates a compiled template function that can interpolate data properties in “interpolate” delimiters, HTML-escape interpolated data properties in “escape” delimiters, and execute JavaScript in “evaluate” delimiters.
const compiled = _.template('hello <%= user %>!');
compiled({ 'user': 'fred' });
// => 'hello fred!'
Previous: Function Methods Next: Utility Methods
Last updated 2 days ago