Syntax, Parameter and Return Value
Syntax:
_.deburr([string=''])
Parameters:
[string=''] (string): The string to deburr.
Return Value:
(string) - Returns the deburred string.
Examples
Removing Accents from a String:
JavaScript
var _ = require('lodash');
var text = 'déjà vu';
console.log(_.deburr(text));

You can also try this code with Online Javascript Compiler
Run Code
Output:
'deja vu'
Demonstrates converting a string with accents into a basic Latin equivalent.
Preparing String for URL Slug:
JavaScript
var title = 'Café au lait';
var slug = _.deburr(title).toLowerCase().replace(/\s+/g, '-');
console.log(slug);

You can also try this code with Online Javascript Compiler
Run Code
Output:
'cafe-au-lait'
Shows how to create a URL-friendly slug from a string with accents.
Standardizing Text for Search:
JavaScript
var searchQuery = 'fiancée';
var standardizedQuery = _.deburr(searchQuery).toLowerCase();
console.log(standardizedQuery);

You can also try this code with Online Javascript Compiler
Run Code
Output:
'fiancee'
An example of standardizing a search query by removing diacritical marks.
Processing User Input:
JavaScript
var userInput = 'El Niño';
var processedInput = _.deburr(userInput);
console.log(processedInput);

You can also try this code with Online Javascript Compiler
Run Code
Output:
'El Nino'
Demonstrates processing user input to remove special characters for consistency.
Frequently Asked Questions
How does _.deburr() handle non-Latin characters?
_.deburr() is specifically designed for Latin-1 Supplement and Latin Extended-A characters. Non-Latin characters (like Cyrillic, Chinese, etc.) are not affected by this method.
Can _.deburr() be used for all language texts?
While _.deburr() is useful for texts in languages that use Latin characters with diacritical marks, it may not be suitable for languages that rely on non-Latin scripts.
Does _.deburr() affect the case of letters?
No, _.deburr() does not change the case of letters. It only removes accents and diacritical marks from Latin characters.
Conclusion
Lodash's _.deburr() method is a valuable tool for simplifying strings by converting characters with diacritical marks to their basic Latin equivalents. It is particularly beneficial in contexts where standardization of text is required, such as in search functionality, URL slug generation, and cross-system data handling.
You can refer to our guided paths on the Coding Ninjas. You can check our course to learn more about DSA, DBMS, Competitive Programming, Python, Java, JavaScript, etc.
Also, check out some of the Guided Paths on topics such as Data Structure and Algorithms, Competitive Programming, Operating Systems, Computer Networks, DBMS, System Design, etc., as well as some Contests, Test Series, and Interview Experiences curated by top Industry Experts.