score:2

Accepted answer
params: {
   ...(ID && {
      ID: ID
    }) // conditional spread operator
}

score:2

const parameters = condition ? {ID: id, Name: name} : {};
axios.get('/user', {
params: parameters
})
.then(function (response) {
console.log(response);
})

Related Query

More Query from same tag