0

Why this code worked for me, i want to do a request

const ChangeSettings= (flag)=>{

    await client.put(`${MyEndpoint}/${car}`, {
      flag,
    })

but when i copy in a new var, dont work

const ChangeSettings = (flag)=>{

    let copyFlag=flag
        await client.put(`${MyEndpoint}/${car}`, {
          copyFlag,
        })

what is the wrong?

  • 1
    Does this answer your question? [Javascript object literal: what exactly is {a, b, c}?](https://stackoverflow.com/questions/34414766/javascript-object-literal-what-exactly-is-a-b-c) – Emile Bergeron May 26 '20 at 02:48

1 Answers1

2

flag is an object which has a key flag and you are passing an object copyFlag with a key copyFlag. Hence the issue

Use this

const updateUserSettingsInfo = (flag)=>{

    let copyFlag=flag
        await client.put(`${MyEndpoint}/${car}`, {
          flag: copyFlag, //<---- change the key of an object
        })

side note - since you are awaiting in your function, make sure to use async

const updateUserSettingsInfo = async (flag) => {
...
gdh
  • 10,036
  • 2
  • 5
  • 19