by @saigowthamr

How to make copy of a string in JavaScript

Home » javascript » How to make copy of a string in JavaScript

JavaScript has a built-in slice() method by using that we can make a copy of a string.

Example:

const str = "apple";

const copy = str.slice();

console.log(copy); // "apple"

Similary, you can do it by assigning the old string to a new variable.

const str = "apple";

const copy = str;

console.log(copy); // "apple