Home > Back-end >  How to shift a text in node.js
How to shift a text in node.js

Time:02-26

I remember there was a function in node.js named shift that worked like this:

"hello".shift(/*amount*/ 1)

and it gave "ello" but now it gives error

please tell me the function name or tell me if it even exists

CodePudding user response:

Try:

"Hello".substring(1)

CodePudding user response:

The function .shift(...) is a prototype of Array.

An alternative function is to use this function:

function Shift(text) {
  var arr = text.split("");
  arr.shift();
  var originalString = arr.join("");
  return originalString;
}
  • Related