当前位置: 首页>>编程示例 >>用法及示例精选 >>正文


Lodash _.trimEnd()用法及代码示例

Lodash是一个JavaScript库,可在underscore.js之上运行。 Lodash帮助处理数组,字符串,对象,数字等。

_.trimEnd()方法用于从给定字符串的末尾删除结尾的空格或指定的字符。

用法:

_.trimEnd( string, chars )

参数: 此方法接受上面提到和下面描述的两个参数:

  • string:它是必须修剪的字符串。默认值为空字符串。
  • chars:它是必须从字符串中修剪掉的一组字符。它是一个可选参数。默认值为空白。

返回值:此方法返回修剪后的字符串。



范例1:

Javascript

// Defining Lodash variable  
const _ = require('lodash');  
  
// The string to trim 
var str = "   Geeks-for-Geeks   "; 
  
// Using _.trimEnd() method 
console.log(_.trimEnd(str));

输出:

"   Geeks-for-Geeks"

范例2:

Javascript

// Defining Lodash variable  
const _ = require('lodash');  
  
// The string to trim 
var str = "----GeeksforGeeks----"; 
  
// Using _.trimEnd() method 
// with specific characters to trim 
console.log(_.trimEnd(str, "-"))

输出:

"----GeeksforGeeks"

相关用法


注:本文由纯净天空筛选整理自taran910大神的英文原创作品 Lodash _.trimEnd() Method。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。