Skip to content

Instantly share code, notes, and snippets.

@TunvirRahman
Last active May 7, 2021 21:46
Show Gist options
  • Select an option

  • Save TunvirRahman/9f06f25e4557b10a8247f902b07fe06d to your computer and use it in GitHub Desktop.

Select an option

Save TunvirRahman/9f06f25e4557b10a8247f902b07fe06d to your computer and use it in GitHub Desktop.
const someObject = {
title: null,
subTitle: "Subtitle",
buttonColor: null,
disabled: true
};
function createOption(someObject) {
someObject.title = someObject.title || "Default Title";
someObject.subTitle = someObject.subTitle || "Default Subtitle";
someObject.buttonColor = someObject.buttonColor || "blue";
someObject.disabled = someObject.disabled !== undefined ? someObject.disabled : true;
return someObject
}
console.log(createOption(someObject));
// Output be like
// {title: 'Default Title', subTitle: 'Subtitle', buttonColor: 'blue', disabled: true}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment