I have a function that adds a key to incoming object, but I have been told to use the spread operator for that, I have been told that I can use the spread operator to create a new object with the same properties and then set isAvailable on it.
return new Partner(ServerConfig, capabilities, initialState) } class Partner { constructor (ServerConfig, capabilities, initialState) { initialState.isAvailable = true So I tried something like this but couldn't succeed, can you help me? and confused, should I use the spread operator in this way, return from a function ?
newObject = {} // use this inside a function and get value from return return { value: { ...newObject, ...initialState } } initialState.isAvailable = true
...isn't an operator. It's syntax, notation, but not an operator (like the()in aforstatement).