Functions / Turf.js / turf.clone
Turf.jsTransformation

turf.clone

What is turf.clone?

turf.clone returns a deep copy of any GeoJSON input. It is purpose-built for GeoJSON and significantly faster than the common JSON.parse(JSON.stringify(feature)) idiom, preserving numeric precision and handling only the fields GeoJSON is expected to contain.

JavaScript
turf.clone(geojson) → Feature<Geometry>

When would you use turf.clone?

Use turf.clone before mutating a feature in place. Many Turf functions accept a mutate option — when you do not want the side-effects, clone first. It is also useful when you want to hand a feature to multiple map sources in MapLibre or Mapbox and prevent accidental cross-layer edits.

In React or similar immutable-data architectures, turf.clone lets you produce a fresh copy of a feature before running a transformation so that state changes remain predictable and shallow comparisons work.

Code
undefined

FAQs

Is it faster than JSON.parse(JSON.stringify())?

Yes — typically 2–5× faster for GeoJSON because it knows the structure and skips generic reflection. For a small feature the difference is negligible; for a FeatureCollection with thousands of features it is significant.

Does it preserve the feature id and bbox?

Yes. turf.clone copies id, bbox, properties, and coordinates. It does not try to compute a new bbox — if you want a refreshed bbox after a transformation, call turf.bbox explicitly.

How do I install just clone?

npm install @turf/clone. It has only @turf/helpers as a dependency.

Does it handle non-standard properties?

Yes — arbitrary properties fields are deep-cloned. If properties contain functions or non-serialisable values, behaviour may differ from JSON.parse(JSON.stringify(...)). Keep properties JSON-safe.