Creates a shallow clone of the given object.
The type of the object.
The object to clone.
// Clone a primitive valuesconst num = 29;const clonedNum = clone(num);console.log(clonedNum); // 29console.log(clonedNum === num) ; // true Copy
// Clone a primitive valuesconst num = 29;const clonedNum = clone(num);console.log(clonedNum); // 29console.log(clonedNum === num) ; // true
// Clone an arrayconst arr = [1, 2, 3];const clonedArr = clone(arr);console.log(clonedArr); // [1, 2, 3]console.log(clonedArr === arr); // false Copy
// Clone an arrayconst arr = [1, 2, 3];const clonedArr = clone(arr);console.log(clonedArr); // [1, 2, 3]console.log(clonedArr === arr); // false
// Clone an objectconst obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };const clonedObj = clone(obj);console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }console.log(clonedObj === obj); // false Copy
// Clone an objectconst obj = { a: 1, b: 'es-toolkit', c: [1, 2, 3] };const clonedObj = clone(obj);console.log(clonedObj); // { a: 1, b: 'es-toolkit', c: [1, 2, 3] }console.log(clonedObj === obj); // false
Alias