Removing string characters from the beginning using drop
In this approach, we are using Lodash’s drop method on the string str by first splitting it into an array of characters, then dropping the first 3 characters from it, and finally joining the remaining characters back into a string stored in res, which is then logged to the console.
Syntax:
_.drop(str.split(''), numberOfElementsToBeRemoved).join('')
Example: The below example uses the drop method to drop elements from the beginning of the string.
const _ = require('lodash');
const str = 'Hello, GFG!';
const res = _.drop(str, 3).join('');
console.log(res);
Output:
lo, GFG!
How to use the drop method in Lodash ?
The Drop method in Lodash removes elements from the beginning of arrays or characters from the start of strings. You can implement the lodash drop method as implemented in the below approaches.
Table of Content
- Removing elements from the beginning of an array using drop
- Removing string characters from the beginning using drop
Run the below command before running the below code on your system:
npm i lodash