Determine if JSON Object contains a value

Posted on 2011-10-04
Last Modified: 2012-05-12
I am creating a JSON object like this:
    window.attendees              = {};
    window.attendees.eventcode    = "GEVENT";
    window.attendees.price        = 169;
    window.attendees.WaitingList  = "";
    window.attendees.participants = [];

Open in new window

and populating it like this:
  function addParticipant() {
    var participant = {};
    // want to check here if the email to be added already exists in window.attendees.participants
    var valid = $('#checkout-step-billing .voucher_form').validationEngine('validate');
    if (valid) {
      participant.firstname   = $('#firstname').val();
      participant.lastname    = $('#lastname').val();
      participant.DOB         = $('#DOB').val();
      participant.Last4       = $('#Last4SSN').val();
      participant.PID         = $('#customer_id').val();
      participant.Phone       = $('#Phone').val();
      participant.Employer    = $('#Employer').val();
      participant.Address     = $('#Address').val();
      participant.City        = $('#City').val();
      participant.State       = $('#State').val();
      participant.Zip         = $('#Zip').val();       = $('#SomeoneElseEmail').val();
    } // if (valid)
  } // function addParticipant()

Open in new window

I need to prevent the same email address from being added twice if it already exists in window.attendees.participants.
Question by:EddieShipman
    1 Comment
    LVL 81

    Accepted Solution

    function emailIsNotFound(arrParticipants, str) {
        for(var i=0;i<arrParticipants.length;i++) {
           if( arrParticipants[i]["email"] == str ) return false;
        return true;

    Open in new window

    use :

      function addParticipant() {
        var participant = {};
        if( emailIsNotFound( window.attendees.participants, $('#SomeoneElseEmail').val() ) ) {

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    Course: HTML5 Mobile App Development with PhoneGap

    PhoneGap can help you leverage your already existing HTML5, JavaScript, and CSS skills in order to create and deploy cross-platform mobile apps.This program comprehensively covers HTML5 mobile app development from top to bottom.

    This article discusses the difference between strict equality operator and equality operator in JavaScript. The Need: Because JavaScript performs an implicit type conversion when performing comparisons, we have to take this into account when wri…
    JavaScript can be used in a browser to change parts of a webpage dynamically. It begins with the following pattern: If condition W is true, do thing X to target Y after event Z. Below are some tips and tricks to help you get started with JavaScript …
    The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
    The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

    760 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    8 Experts available now in Live!

    Get 1:1 Help Now