How to optimize the 3 conditions if else if Statements - javascript

Hi i have to check the three conditions, is there any Way to optimize the code other than the if else if statements. if i am checking all the three combinations its going to more lines of code do we have any better option to check all the conditions. Please can anybody help me on this to optimize the code.
if (req.body.officeId === "null" && req.body.branchId === "null" && req.body.productId === "null") {
updatedTestData = _.omit(req.body, ['officeId', 'branchId', 'roomId']);
updatedTestData.officeId = null;
updatedTestData.office = {};
updatedTestData.branchId = null;
updatedTestData.branch = {};
updatedTestData.productId = null;
updatedTestData.product = {};
} else if (req.body.officeId === "null" && req.body.branchId === "null" && !req.body.productId === "null") {
updatedTestData = _.omit(req.body, ['officeId', 'branchId']);
updatedTestData.officeId = null;
updatedTestData.office = {};
updatedTestData.branchId = null;
updatedTestData.branch = {};
}

Use Array.prototype.every():
var condition = [ req.body.officeId, req.body.branchId, req.body.productId]
if (condition.every(item => item === "null") {
// do some work
}
if (condition.every(item => item !== "null") {
// do other work
}
every will automatically exit if it finds a false value, so you will only have to go through your conditions until they fail.

A slightly better version:
if(req.body.officeId === "null" && req.body.branchId === "null"){
if(req.body.productId === "null"){
//your first code block
}else{
//your second code block
}
}

This might help
if (req.body.officeId === "null" && req.body.branchId === "null") {
if (req.body.productId === "null"){
updatedTestData = _.omit(req.body, ['officeId', 'branchId', 'roomId']);
updatedTestData.officeId = null;
updatedTestData.office = {};
updatedTestData.branchId = null;
updatedTestData.branch = {};
updatedTestData.productId = null;
updatedTestData.product = {};
return
}
updatedTestData = _.omit(req.body, ['officeId', 'branchId']);
updatedTestData.officeId = null;
updatedTestData.office = {};
updatedTestData.branchId = null;
updatedTestData.branch = {};
}

2 of the checks are common to both the if and elseif so you could extract those to an outer if...
if (req.body.officeId === "null" && req.body.branchId === "null") {
if (req.body.productId === "null") {
updatedTestData = _.omit(req.body, ['officeId', 'branchId', 'roomId']);
updatedTestData.officeId = null;
updatedTestData.office = {};
updatedTestData.branchId = null;
updatedTestData.branch = {};
updatedTestData.productId = null;
updatedTestData.product = {};
} else {
updatedTestData = _.omit(req.body, ['officeId', 'branchId']);
updatedTestData.officeId = null;
updatedTestData.office = {};
updatedTestData.branchId = null;
updatedTestData.branch = {};
}
}

var array = ['officeId', 'branchId'];
var body = req.body;
var office = body.officeId;
var branch= body.branchId;
var product= body.productId;
if(office === 'null' && branch === 'null') {
if(product !== 'null') {
array.push('roomId');
updatedTestData = _.omit(body, array);
testChange(body, 'product', updatedTestData);
} else {
}
}
testChange(req.body, 'office', updatedTestData);
testChange(req.body, 'branch', updatedTestData);
function testChange(object, key, toChange) {
if(object[key] === 'null') {
toChange[key + 'Id'] = null;
toChange[key] = {};
}
}

One more approach in ES 5:
var isNull = function(items) {
if (items === null) return true;
if (items.length) {
return items.reduce(
function(p, c){
return ((c===null) && p);
}, true);
}
return false;
}
if (isNull([req.body.officeId,
req.body.branchId,
req.body.productId]))
{
//
}
else if (isNull([req.body.officeId,
req.body.branchId] && !isNull(req.body.productId))
{
//
}

Related

Leetcode Same Tree Iterative Solution

Question at hand: https://leetcode.com/problems/same-tree/
Can someone point out why my JavaScript solution can pass the test cases but fails during the actual submission?
var isSameTree = function(p, q) {
let queue = [];
queue.push(p);
queue.push(q);
while (!queue.length) {
let p = queue.shift();
let q = queue.shift();
if (p == null && q == null) {
continue;
} else if (p == null || q == null || p.val != q.val) {
return false;
} else {
queue.push(p.left);
queue.push(q.left);
queue.push(p.right);
queue.push(q.right);
}
}
return true;
};
#trincot mentioned it in the comments.
Just update the comparison inside the while loop to get into that loop.
var isSameTree = function(p, q) {
let queue = [];
queue.push(p);
queue.push(q);
while (queue.length != 0) {
let p = queue.shift();
let q = queue.shift();
if (p == null && q == null) {
continue;
} else if (p == null || q == null || p.val != q.val) {
return false;
} else {
queue.push(p.left);
queue.push(q.left);
queue.push(p.right);
queue.push(q.right);
}
}
console.log(queue);
return true;
};
This will pass all the test cases.

Better way of setting default value

At the moment I'm setting my default values this way:
var ls = localStorage.get('app')
if (ls && typeof ls.installDate !== typeof undefined) { var installDate = ls.installDate } else { var installDate = false }
if (ls && typeof ls.settingsTab !== typeof undefined) { var settingsTab = ls.settingsTab } else { var settingsTab = '' }
if (ls && typeof ls.aboutTab !== typeof undefined) { var aboutTab = ls.aboutTab } else { var aboutTab = true }
plus extra 30 other values. I'm thinking if there is a better (shorter) way to solve this type of approach.
You can do the short cut in script as :
var ls = localStorage.get('app');
You can do like :
var installDate = (ls && ls.installDate) || false;
var settingsTab = (ls && ls.settingsTab) || false;
var aboutTab = (ls.aboutTab) || false;

Is there a polyfill for findAll

I am using JavaScript findAll for a selector engine. Is there any polyfill for the findAll function. I tried to create my own selector engine with this code:
function CTfind(string, context){
var result = [], finalResult = [];
if(typeof string === "object"){
result.push(string);
return result;
}
if(/<([a-zA-Z]+)(\s*)?\/>/ig.test(string)){
var str = string.replace(/<([a-zA-Z]+)(\s*)?\/>/ig, "$1");
var ret = document.createElement(str);
if(typeof context === "object"){
for(i in context)
ret[i] = context[i];
}
document.body.appendChild(ret);
result.push(ret);
return result;
} else{
if(typeof string !== "string" && typeof string !== "object") return false;
var documentElements = context.getElementsByTagName("*"),
toMatch = string.split(", ");
for(i = 0; i < documentElements.length; i++){
for(e = 0; e < toMatch.length; e++){
var stringParts = toMatch[e].split(" ");
for(s = 0; s < stringParts.length; s++){
var parts;
if(/(\.|\#|\:)/g.test(stringParts[s])){
parts = stringParts[s].match(/([A-Za-z]+|[\.\#\:]+[^\.\#\:]+)/g);
} else if(/^(?!(\.|\#|\:)$).*$/g.test(stringParts[s])){
parts = stringParts[s];
var onlyElem = true;
}
if(onlyElem === true){
console.log(documentElements[i].nodeName);
if(documentElements[i].nodeName.toLowerCase() === parts){
result.push(documentElements[i]);
}
} else{
var containsClass = false,
containsElem = false,
containsID = false,
containsPseudo = false,
matchID = false,
matchElem = false,
matchClass = false,
matchPseudo = false;
if(/\./.test(stringParts[s])){
containsClass = true;
}
if(/\#/.test(stringParts[s])){
containsID = true;
}
if(/\:/.test(stringParts[s])){
containsPseudo = true;
}
if(/[^\.\#\:](.*)/.test(stringParts[s])){
containsElem = true;
}
if(containsElem === true){
var elem;
for(g = 0; g < parts.length; g++){
if(/^([^\.\#\:][A-Za-z])*$/.test(parts[g])){
elem = parts[g];
} else{
elem = documentElements[i].nodeName.toLowerCase();
}
}
if(documentElements[i].nodeName.toLowerCase() === elem){
matchElem = true;
}
} else{
matchElem = true;
}
if(containsID === true){
var id = filter(parts, "#");
id = id[0].substr(1);
if(getAttr(documentElements[i], "id") === id){
matchID = true;
}
} else{
matchID = true;
}
if(containsClass === true){
var classes = filter(parts, ".");
if(typeof classes === "string"){
classes = classes[0].split(".");
for(c = 0; c < classes.length; c++){
if(classes[c] !== ""){
if(hasClass(documentElements[i], classes[c])){
matchClass = true;
}
}
}
}
} else{
matchClass = true;
}
if(matchClass && matchID && matchElem){
result.push(documentElements[i]);
}
console.log(result);
}
}
if(stringParts.length > 1){
console.log(result);
if(isDescendant(result[0], result[result.length - 1])){
finalResult.push(result[result.length - 1]);
}
}
}
}
return finalResult;
}
};
But I thought using Javascript findAll would be much easier. Also, I can't use querySelector because sometimes I need to find it in a specific node.

How to fix and work with tree toc?(old syntax)

so i bought a site witch is connected to a gestional programm in office..
the site is a little old, it's fully compatible with all the versions of internet explorer but not with other browsers(opera,safari,chrome,firefox...)
the only piece not working is a menu not opening correctly, when you click on it it doesn't happen anything or in chrome it changes the image but it doesn't upload the links. it seems that it doens't upload things in the hiddenframe...
in chrome it gives error in loadchildren function.
in firefox it gives error in function Toc_click ()
TypeError: window.event is undefined
[Break On This Error]
var eSrc = window.event.srcElement;
we searched for the problem and we think that the problem should be in this file
the problem should be a syntax problem, it's compatible in old browsers but not on the new ones. i cannot change completely the code as it is connected with other files(a lot) and sql server...
we already tried to change
document.frames["hiddenframe"].location.replace(strLoc);
by
document.getElementsByName("hiddenframe").location.replace(strLoc);
it doens't work and it doesn't work on IE either...
/* TOC.JS */
var framesTop = parent.parent;
//var L_LoadingMsg_HTMLText = "Loading, click to cancel...";
var LoadDiv = '<DIV ONCLICK="loadFrame(true);" CLASS="clsLoadMsg">';
L_LoadingMsg_HTMLText = LoadDiv + L_LoadingMsg_HTMLText + "</LI>";
function caps(){
var UA = navigator.userAgent;
if(UA.indexOf("MSIE") != -1)
{
this.ie = true;
this.v = UA.charAt(UA.indexOf("MSIE") + 5);
if( this.v == 2 ) this.ie2 = true;
else if( this.v == 3 ) this.ie3 = true;
else if( this.v == 4 ) this.ie4 = true;
else if( this.v == 5 ) this.ie5 = true;
else if( this.v == 6 ) this.ie6 = true;
else this.ie6 = true;
}
else if(UA.indexOf("Mozilla") != -1 && UA.indexOf("compatible") == -1)
{
this.nav = true;
var v = UA.charAt(UA.indexOf("Mozilla") + 8);
if(v == 2 ) this.nav2 = true;
else if(v == 3 ) this.nav3 = true;
else if(v == 4 ) this.nav4 = true;
}
if(UA.indexOf("Windows 95") != -1 || UA.indexOf("Win95") != -1 || UA.indexOf("Win98") != -1 || UA.indexOf("Windows 98") != -1 || UA.indexOf("Windows NT") != -1 || UA.indexOf("Windows XP") != -1) this.win32 = true;
else if(UA.indexOf("Windows 3.1") != -1 || UA.indexOf("Win16") != -1) this.win16 = true;
else if(UA.indexOf("Mac") != -1) this.anymac = true;
else if(UA.indexOf("SunOS") != -1 || UA.indexOf("HP-UX") != -1 || UA.indexOf("X11") != -1) this.unix = true;
else if(UA.indexOf("Windows CE") != -1) this.wince = true;
}
var bc = new caps();
////////////////////////////////////////////
// Not sure why this is here, it puts a scrollbar up when none is needed
// if("object" == typeof(parent.document.all.fraPaneToc)) parent.document.all.fraPaneToc.scrolling = "yes";
////////////////////////////////////////////
var eSynchedNode = null;
var eCurrentUL = null;
var eCurrentLI = null;
var bLoading = false;
function loadFrame( bStopLoad )
{
if( "object" == typeof( eCurrentUL ) && eCurrentUL && !bStopLoad )
{
eCurrentUL.innerHTML = hiddenframe.chunk.innerHTML;
eCurrentUL = null;
bLoading = false;
}
else if( "object" == typeof( eCurrentUL ) && eCurrentUL )
{
eCurrentUL.parentElement.children[1].className = "";
eCurrentUL.parentElement.children[0].src = "bs.gif";
eCurrentUL.parentElement.className = "kid";
eCurrentUL.className = "clsHidden";
eCurrentUL.innerHTML="";
eCurrentUL = null;
bLoading = false;
}
else
{
bLoading = false;
}
return;
}
function GetNextUL(eSrc)
{
var eRef = eSrc;
for(var i = eRef.sourceIndex + 1; i < document.all.length; i++)
{
if( "UL" == document.all[ i ].tagName )
{
return document.all[ i ];
}
else if( "LI" == document.all[ i ].tagName )
{
break;
}
}
return false;
}
function MarkSync(eSrc)
{
if("object" == typeof(aNodeTree)) aNodeTree = null;
if("LI" == eSrc.tagName.toUpperCase() && eSrc.children[1] && eSynchedNode != eSrc )
{
UnmarkSync();
eSrc.children[1].style.fontWeight = "bold";
eSynchedNode = eSrc;
}
}
function UnmarkSync()
{
if("object" == typeof(eSynchedNode) && eSynchedNode )
{
eSynchedNode.children[1].style.fontWeight = "normal";
eSynchedNode = null;
}
}
function MarkActive(eLI)
{
if( "object" == typeof( eLI ) && eLI && "LI" == eLI.tagName.toUpperCase() && eLI.children[1] && eLI != eCurrentLI )
{
MarkInActive();
window.eCurrentLI = eLI;
window.eCurrentLI.children[1].className = "clsCurrentLI";
}
}
function MarkInActive()
{
if( "object" == typeof( eCurrentLI ) && eCurrentLI )
{
window.eCurrentLI.children[1].className = "";
window.eCurrentLI = null;
}
}
function LoadChildren( eLink )
{
var strLoc = "loadtree.asp" + eLink.href.substring( eLink.href.indexOf( "?" ) );
document.frames["hiddenframe"].location.replace(strLoc);
}
function Navigate_URL( eSrc )
{
var eLink = eSrc.parentElement.children[1];
urlIdx = eLink.href.indexOf( "URL=" );
if("object" == typeof(framesTop.fraTopic) && eLink && "A" == eLink.tagName && urlIdx != -1 )
{
if(eLink.target=="fraTopic"||eLink.target=="_top"){
framesTop.fraTopic.location.href = eSrc.parentElement.children[1].href.substring( urlIdx + 4 );
}else{
window.open(eSrc.parentElement.children[1].href,eLink.target);
}
MarkSync(eSrc.parentElement);
}
else if("object" == typeof(framesTop.fraTopic) && eLink && "A" == eLink.tagName && eLink.href.indexOf( "tocPath=" ) == -1 && eLink.href.indexOf( "javascript:" ) == -1 )
{
if(eLink.target=="fraTopic")
{
framesTop.fraTopic.location.href = eSrc.parentElement.children[1].href;
}
else if( eLink.target=="_top" )
{
top.location = eLink.href;
return;
}
else
{
window.open(eSrc.parentElement.children[1].href,eLink.target);
}
MarkSync(eSrc.parentElement);
}
else if( eSynchedNode != eSrc.parentElement && ( urlIdx != -1 || ( eLink.href.indexOf( "javascript:" ) == -1 && eLink.href.indexOf( "tocPath=" ) == -1 ) ) )
{
// START D.S.
if(eLink.target=="fraTopic")
{
if (navigator.userAgent.indexOf("Windows") == -1) {
var MyHref = eSrc.parentElement.children[1].href;
do
{
if (MyHref.indexOf("%2E") != -1) MyHref = MyHref.replace("%2E", ".");
else if (MyHref.indexOf("%2F") != -1) MyHref = MyHref.replace("%2F", "/");
else if (MyHref.indexOf("%3F") != -1) MyHref = MyHref.replace("%3F", "?");
else if (MyHref.indexOf("%3D") != -1) MyHref = MyHref.replace("%3D", "=");
else if (MyHref.indexOf("%26") != -1) MyHref = MyHref.replace("%26", "&");
else break;
}
while (true);
parent.fraTopic.location.href = MyHref;
} else {
parent.fraTopic.location.href = eSrc.parentElement.children[1].href;
}
}
// END D.S.
MarkSync( eSrc.parentElement );
}
}
function Image_Click( eSrc , bLeaveOpen )
{
var eLink = eSrc.parentElement.children[1];
if("noHand" != eSrc.className)
{
eLI = eSrc.parentElement;
MarkActive(eLI);
var eUL = GetNextUL(eLI);
if(eUL && "kidShown" == eLI.className)
{
// hide on-page kids
if( !bLeaveOpen )
{
eLI.className = "kid";
eUL.className = "clsHidden";
eSrc.src = "bs.gif";
}
}
else if(eUL && eUL.all.length)
{
// show on-page kids
eLI.className = "kidShown";
eUL.className = "clsShown";
eSrc.src = "bo.gif";
}
else if("kid" == eLI.className)
{
// load off-page kids
if( !bLoading )
{
bLoading = true;
eLI.className = "kidShown";
eUL.className = "clsShown";
window.eCurrentUL = eUL;
eSrc.src = "bo.gif";
eUL.innerHTML = L_LoadingMsg_HTMLText;
LoadChildren( eLink );
}
}
}
}
function Toc_click ()
{
var eSrc = window.event.srcElement;
event.returnValue = false;
if("A" == eSrc.tagName.toUpperCase() && "LI" == eSrc.parentElement.tagName)
{
var eImg = eSrc.parentElement.children[0];
if(eImg) eImg_click(eImg);
}
else if("SPAN" == eSrc.tagName && "LI" == eSrc.parentElement.tagName)
{
var eImg = eSrc.parentElement.children[0];
if(eImg) eImg_click(eImg);
}
else if("IMG" == eSrc.tagName)
{
}
return event.returnValue;
}
function eImg_click(eImg)
{
if("IMG" == eImg.tagName)
{
Image_Click( eImg , false );
Navigate_URL( eImg );
}
}
function Toc_dblclick()
{
return;
}
function window_load()
{
if( self == top ) location.replace( "default.asp" );
var objStyle = null;
if( bc.win32 && ( bc.ie4 || bc.ie5 || bc.ie6 ) && "object" == typeof ( ulRoot ) && "object" == typeof( objStyle = document.styleSheets[0] ) && "object" == typeof( objStyle.addRule ) )
{
window.eSynchedNode = document.all["eSynchedNode"];
objStyle.addRule( "UL.clsHidden" , "display:none" , 0 );
objStyle.addRule( "UL.hdn" , "display:none" , 0 );
//--ulRoot.onclick=Toc_click;
ulRoot.ondblclick=Toc_dblclick;
if( window.eSynchedNode )
{
MarkActive(window.eSynchedNode);
window.eSynchedNode.all.tags( "B" )[0].outerHTML = eSynchedNode.all.tags("B")[0].innerHTML;
window.scrollTo(0,window.eSynchedNode.offsetTop-(document.body.clientHeight/2));
}
else
{
MarkActive(document.all.tags( "LI" )[0]);
}
}
}
window.onload = window_load;
suggestions?

How to import data of gmail contacts, using javascript Google Contact API, in more detailed format?

I'm using code from this page http://code.google.com/apis/contacts/docs/1.0/developers_guide_js.html to get list of gmail contacts. Actually it works ok, but I get data of name, address, etc like a simple string, with "\n" as separator, for example:
<script type="text/javascript">
var contactsService;
var scope = 'https://www.google.com/m8/feeds';
function setupContactsService() {
//contactsService = new google.gdata.contacts.ContactsService('exampleCo-exampleApp-1.0');
contactsService = new google.gdata.contacts.ContactsService('GoogleInc-jsguide-1.0');
}
function getMyContacts() {
var contactsFeedUri = 'https://www.google.com/m8/feeds/contacts/default/full'; //?max-results=9999&alt=json&v=3.0
var query = new google.gdata.contacts.ContactQuery(contactsFeedUri);
setupContactsService();
contactsService.getContactFeed(query, handleContactsFeed, handleError);
}
var handleContactsFeed = function(result) {
var entries = result.feed.entry;
for (var i = 0; i < entries.length; i++) {
var entry = entries[i];
var addrs = entry.getPostalAddresses();
var name = entry.getTitle();
// logging
console.log(addrs[0]);
console.log(name);
}
}
function handleError(e) {
alert(e.cause ? e.cause.statusText : e.message);
}
</script>
it gives me an object where name and address values are simple strings.
Can I get somehow data in like associative array format, where address will contains separate values of street, zip, city, country; and name separate values of first name, last name etc.
Like:
{
"type": "address",
"value":
{
"street": "Starret 1234",
"city": "City name",
"stateOrProvince": "ca",
"postalCode": "73000",
"country": "USA"
}
},
{
"type": "name",
"value":
{
"firstName": "Allen",
"lastName" : "Iverson",
.....
}
}
Thanks in advance!
Seems I found an answer, for get more detailed and formatted info need to add additional parameter to contactsFeedUri for google.gdata.contacts.ContactQuery.
This additional parameter is: ?v=3.0
So in my case function will looks like:
function getMyContacts() {
var contactsFeedUri = 'https://www.google.com/m8/feeds/contacts/default/full?v=3.0&alt=json';
var query = new google.gdata.contacts.ContactQuery(contactsFeedUri);
setupContactsService();
contactsService.getContactFeed(query, handleContactsFeed, handleError);
}
And for get necessary data I create a simple obj, which can be useful for somebody:
function contactEntry(entry) {
this.entry = entry;
this.testEntry = function() {
alert( 'test entry' )
};
this.getFirstName = function() {
if ((entry.gd$name == null) || (entry.gd$name.gd$givenName == null) || (entry.gd$name.gd$givenName.$t == null)) {
return '';
} else {
return entry.gd$name.gd$givenName.$t;
}
};
this.getLastName = function() {
if ((entry.gd$name == null) || (entry.gd$name.gd$familyName == null) || (entry.gd$name.gd$familyName.$t == null)) {
return '';
} else {
return entry.gd$name.gd$familyName.$t;
}
};
this.getAdditionalName = function() {
if ((entry.gd$name == null) || (entry.gd$name.gd$AdditionalName == null) || (entry.gd$name.gd$AdditionalName.$t == null)) {
return '';
} else {
return entry.gd$name.gd$familyName.$t;
}
};
this.getEmail = function() {
if ((entry.gd$email == null) || (entry.gd$email.length == 0) || (entry.gd$email[0].address == null)) {
return '';
} else {
return entry.gd$email[0].address;
}
};
this.getStreet = function() {
if (!this._addrExists() || (entry.gd$structuredPostalAddress[0].gd$street == null)) {
return '';
} else {
return entry.gd$structuredPostalAddress[0].gd$street.$t;
}
};
this.getCity = function() {
if (!this._addrExists() || (entry.gd$structuredPostalAddress[0].gd$city == null)) {
return '';
} else {
return entry.gd$structuredPostalAddress[0].gd$city.$t;
}
};
this.getCountry = function() {
if (!this._addrExists() || (entry.gd$structuredPostalAddress[0].gd$country == null)) {
return '';
} else {
return entry.gd$structuredPostalAddress[0].gd$country.$t;
}
};
this.getPostcode = function() {
if (!this._addrExists() || (entry.gd$structuredPostalAddress[0].gd$postcode == null)) {
return '';
} else {
return entry.gd$structuredPostalAddress[0].gd$postcode.$t;
}
};
this.getPhone = function() {
if ((entry.gd$phoneNumber == null) || (entry.gd$phoneNumber.length == 0) || (entry.gd$phoneNumber[0].$t == null)) {
return '';
} else {
return entry.gd$phoneNumber[0].$t
}
};
this.getOrganization = function() {
if ((entry.gd$organization == null) || (entry.gd$organization.length == 0) || (entry.gd$organization[0].getOrgName() == null)) {
return '';
} else {
return entry.gd$organization[0].getOrgName().getValue();
}
};
this.getBirthday = function() {
if ((entry.gContact$birthday == null) || (entry.gContact$birthday.when == null)) {
return '';
} else {
return entry.gContact$birthday.when;
}
};
this.getEvent = function() {
if ((entry.gContact$event == null) || (entry.gContact$event.length == 0) || (entry.gContact$event[0].gd$when == null)) {
return '';
} else {
return entry.gContact$event[0].gd$when.startTime;
}
};
// protected methods
this._addrExists = function() {
if ((entry.gd$structuredPostalAddress == null) || (entry.gd$structuredPostalAddress.length == 0)) {
return false;
}
return true;
};
}
It can be used in this way:
var handleContactsFeed = function(result) {
var entries = result.feed.entry;
var contact = new contactEntry(entries[0]);
var address = {};
address['fname'] = contact.getFirstName();
address['lname'] = contact.getLastName() + (contact.getAdditionalName() != '' ? ' ' + contact.getAdditionalName() : '');
address['address'] = contact.getStreet();
address['city'] = contact.getCity();
address['country'] = contact.getCountry();
address['zip'] = contact.getPostcode();
address['phone'] = contact.getPhone();
address['mail'] = contact.getEmail();
address['organization'] = contact.getOrganization();
address['birthday'] = contact.getBirthday();
address['event'] = contact.getEvent();
}

Categories

Resources