Skip to content

Instantly share code, notes, and snippets.

@litanur
Created November 14, 2022 15:05
Show Gist options
  • Save litanur/967b1100016a6b62d065249556d20b4c to your computer and use it in GitHub Desktop.
Save litanur/967b1100016a6b62d065249556d20b4c to your computer and use it in GitHub Desktop.
function checkProperties(obj, email) {
let fullname = "";
for (var key in obj) {
if (obj[key] !== null && obj[key] != "")
fullname = obj[key];
break;
}
if (fullname != "") {
console.log(fullname)
} else {
const regExp = /^([^@]+)/g;
fullname = email.match(regExp);
console.log(fullname[0]);
}
}
let obj = {
familyName: null,
givenName: null,
middleName: null,
namePrefix: null,
nameSuffix: null,
nickname: null}
let email = "[email protected]";
checkProperties(obj, email)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment