How to use Lodash _.truncate() Method In Javascript
The _.truncate() method of String in lodash is used to truncate the stated string if it is longer than the specified string length.
Syntax:
_.truncate([string=''], [options={}])
Example: In this example, we are using Lodash _.truncate() Method
// Requiring lodash library
const _ = require('lodash');
// Calling _.truncate() method with
// its parameter
let res = _.truncate(
'w3wiki is a computer science portal.');
// Displays output
console.log(res);
Output:
w3wiki is a computer...
How to truncate an array in JavaScript ?
In JavaScript, there are two ways of truncating an array. One of them is using length property and the other one is using splice() method. In this article, we will see, how we can truncate an array in JavaScript using these methods.
These are the following ways to truncate an array:
Table of Content
- Using length Property
- Using splice() Method
- Using slice() Method
- Using Lodash _.truncate() Method
- Using Array.prototype.pop() in a loop
Contact Us