Can't modify string value via callback parameter - how to update object?

8 replies
Last updated: Dec 1, 2025
Hi! I'm struggling with some javascript. Can someone who knows more about JS confirm the following?
I'm trying to modify the value of a string via a callback, but I think my efforts are futile.


var object = {
  item: {
    content: ""
  },
  collection: []
}

function preprocess(callback) {
// ...
}

preprocess(({ collection, content }) => {
    content = "new content"
    collection = ["new-item-1", "new-item-2", "new-item3"];
});

console.log(object.item.content)
// => "new content"
Is there a way to make this work?
AI Update

This question is about general JavaScript concepts (passing values vs references, destructuring, and callbacks) and isn't related to Sanity. You'll get better help posting this in a JavaScript-focused community like:

If you have questions about using JavaScript with Sanity — like writing GROQ queries, creating custom input components, setting up validation functions, or working with Sanity Functions — I'm happy to help with those!

Show original thread
8 replies

Sanity – Build the way you think, not the way your CMS thinks

Sanity is the developer-first content operating system that gives you complete control. Schema-as-code, GROQ queries, and real-time APIs mean no more workarounds or waiting for deployments. Free to start, scale as you grow.

Was this answer helpful?