1

i have to create a custom function that clone objects despite of their types. IE. an array should be copied as an array, string as string etc.

The result of clonedObject = jQuery.extend(true, {}, object); with arrays is an object with numerical indexes, for string is an object of characters with numerical indexes.

There is a better way to make this work than checking the type of the object and writing custom clone functions?

Thanks in advance, Mattia

Mattiag
  • 108
  • 2
  • 10

1 Answers1

0

if you just need a shallow copy you can use as described here

var newCopiedArray=old_array.slice(0);

Check the code snippets here

Community
  • 1
  • 1
Aneesh Mohan
  • 1,077
  • 8
  • 17