API Reference

Returns an object with a new key value pair added if the key does not already exist.

function putNew<T extends Record<string | number, any>>(
  obj: T,
  key: string,
  value: unknown
)

// Example:

const obj = { name: "Stephen", age: 39 }

putNew(obj, "name", "James") //=> { name: "Stephen", age: 39}

putNew(obj, "city", "Atlanta") //=> { name: "Stephen", age: 39, city: "Atlanta" }