I have an array named as joinedArray. In one case, it has the value [undefined, undefined].
I have written one if condition like:
if(joinArray === undefined){
    vm.selectedFriends = [];
    angular.forEach($scope.contacts, function(contact){
        if (contact.selected)
        vm.selectedFriends.push(contact.email);
    });
    $http({
        url: 'http://192.168.2.8:7200/api/creatList',
        method: 'POST',
        data: {wData:userData, uId:vm.uid, userName:vm.uName, email:vm.selectedFriends}
    }).success(function(res) {
        console.log("success");
    }, function(error) {
        console.log(error);
        alert('here');
    });
    $mdDialog.hide(userData);
} else {
    $http({
        url: 'http://192.168.2.8:7200/api/sendMail',
        method: 'POST',
        data: {wData:userData, email:joinArray, uId:vm.uid, userName:vm.uName}
    }).success(function(res) {
        console.log("success");
    }, function(error) {
        console.log(error);
        alert('here');
    });
    $mdDialog.hide(userData);
}
Sometimes joinedArray returns like [value, undefined] or [undefined, value]. But only when both values are undefined should it pass to the if condition, otherwise it should go to else condition.