is there any way to re-assign an object value on the fly using destructuring in es6?

How about the spread operator?

axios.post({
    url,
    headers,
    params: {
       ...user,
       fname: 'Jane' // but here I want to have the fname set to Jane instead of John
    }
}).then(...).catch(...)

You can also use Object.assign like:

Object.assign(user, { fname: 'Jane' })

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top