Return an object but with one property different In the following code I want to return all the same keys and values except the property color. If the name is default, return the color: '#1F2532', if it's different than default, it will call a function that gives me random colors color: pickColor([]). But I think there is a better way to write this instead of repeating code and just changing the property color. How can I do this?

class Project {

  static createProject(data) {
    if (data.name !== 'default') {
      return {
        owner: {
          name: data.owner,
          avatar: data.ownerAvatar
        },
        users: [
          {
            name: data.owner,
            avatar: data.ownerAvatar,
            active: true,
          }],
        name: data.name,
        retrospectives: [],
        color: pickColor([])
      }
    } else {
      return {
        owner: {
          name: data.owner,
          avatar: data.ownerAvatar
        },
        users: [
          {
            name: data.owner,
            avatar: data.ownerAvatar,
            active: true,
          }],
        name: data.name,
        retrospectives: [],
        color: '#1F2532'
      }
    }
  }
}
As said in a comment above, using a conditional assignment would be your best bet:

class Project {

  static createProject(data) {
    return {
      owner: {
        name: data.owner,
        avatar: data.ownerAvatar
      },
      users: [
        {
          name: data.owner,
          avatar: data.ownerAvatar,
          active: true,
        }],
      name: data.name,
      retrospectives: [],
      color: data.name === 'default' ? '#1F2532' : pickColor([])
    }
  }
}