Lodash _.camelCase() 方法
_.camelCase() 方法用于将字符串转换为驼峰式字符串。字符串可以用空格分隔、用破折号分隔,也可以用下划线分隔。
句法:
_.camelCase(string)
参数:此方法接受如上所述和如下所述的单个参数:
- 字符串:此参数保存需要转换为驼峰式字符串的字符串。
返回值:该方法返回驼峰式字符串。
下面的示例说明了 JavaScript 中的 Lodash _.camelCase() 方法:
示例 1:
Javascript
// Requiring the lodash library
const _ = require('lodash');
// Use of _.camelCase() method
var str1 = _.camelCase("Geeks for Geeks");
// Printing the output
console.log(str1);
// Use of _.camelCase() method
var str2 = _.camelCase("GFG-Geeks");
// Printing the output
console.log(str2);
Javascript
// Requiring the lodash library
const _ = require('lodash');
// Use of _.camelCase() method
var str1 = _.camelCase("Geeks__for__Geeks");
// Printing the output
console.log(str1);
// Use of _.camelCase() method
var str2 = _.camelCase("GFG--Geeks");
// Printing the output
console.log(str2);
输出:
geeksForGeeks
gfgGeeks
示例 2:
Javascript
// Requiring the lodash library
const _ = require('lodash');
// Use of _.camelCase() method
var str1 = _.camelCase("Geeks__for__Geeks");
// Printing the output
console.log(str1);
// Use of _.camelCase() method
var str2 = _.camelCase("GFG--Geeks");
// Printing the output
console.log(str2);
输出:
geeksForGeeks
gfgGeeks