1

i have added several mail id's to $scope.MultiEmailsList,then i have assigned single email to $scope.SingleEmail.Now i want to check $scope.SingleEmail with $scope.MultiEmailsList list.

if ($scope.MultiEmailsList.contains($scope.SingleEmail))
 {
    console.log("Mail Id Already Exists");
 }
else
  {
     console.log("Mail Id Not Exists");            
  }

3 Answers 3

1

You can write a very simple function like this:

function existsInArray( arr, item ) {

    for( var i = 0; i < arr.length; i++ ) 
        if( arr[ i ] === item ) return true;

    return false; 

}

Or use Underscore.js inbuilt: _.indexOf( arr, item ); function. :)

Sign up to request clarification or add additional context in comments.

1 Comment

for(var i=0;i<$scope.Email.length;i++) { if($scope.Email[i]===$scope.user.Email) { console.log("Mail Id Alresdy Exists"); } }
0

It will be solve your problem:

if ($scope.Email.indexOf($scope.user.Email) !== -1)
            {
                console.log("Mail Id Already Exists");
            }
            else
            {
                $http({
                    method: 'POST',
                    url: 'index.php/Welcome/Signup',
                    data: $scope.user,
                    headers: {'Content-Type': 'application/x-www-form-urlencode'}
                }).success(function (data) {
                    $scope.Enquiry = data;
                    console.log(data);
                    $location.path('/EnquiryResponse');
                });
            }

5 Comments

i have faced this error : TypeError: Cannot read property 'indexOf' of undefined
Use $scope.Email.indexOf
Where i need to use $scope.Email.indexOf
This isn't supported on all browsers though.
let me know which browser is support this.
0
$scope.MultiEmailsList = ["[email protected]","[email protected]"];
$scope.SingleEmail = "[email protected]";


if(($scope.MultiEmailsList).indexOf($scope.SingleEmail)!= -1){
    console.log("value exists");
}else{
   console.log("value not exists");
}

please check this might help you..

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.