Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9086271
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T21:26:52+00:00 2026-06-16T21:26:52+00:00

I have read multiple articles on here concerning arrays, .each, and other solutions, but

  • 0

I have read multiple articles on here concerning arrays, .each, and other solutions, but none of these have showed me the issue in what I am trying to do.

I want to make it to where a button is clicked, the value of that button is stored, and then compared to values of objects in an array. If a match is found I want that match to be .append into a portion of the page.

I know the button click is registering. I have .append that into the page and been displayed the proper value. I know I can iterate all of the objects in the array with .each and .append them to the page as I have done that as well. However if I just .append employee from the example below I get [object Object] and thus I know my comparison operator is not functioning correctly. Any help if showing me my problem or explaining why it is not working is greatly appreciated.

Here is the button:

<button type="button" id="german" class="searchButton" value="German">German</button>

This is what one line my array looks like

employees = [
{ "firstName":"Alex",    "lastName":"Hagerman",  "language":"German",    "department":"Nuerology",   "position":"Nurse",         "skill":"Infection" },
]

There are more lines but this works for the example.

This is the function I want to compare the button value to the array value. (if I was to just .append employee here I get [object Object])

$(document).ready(function(){
    $('button').click(function(){
        var buttonValue = $(this).val();
        $.each(employees, function (i, employee) {
                if (employee == buttonValue) {
                    $('#resultsView').append('<div class="searchResults">'+employee.firstName+employee.lastName+'<br />'+employee.language+'<br />'+employee.department+employee.position+'<br />'+employee.skill+'</div>');
            }
                else {
                    $('#resultsView').append('<div id="resultsView" class="noResult">No results found</div>');
                }

        });
    });
});

Currently I only get No Results Found.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T21:26:53+00:00Added an answer on June 16, 2026 at 9:26 pm

    You’ve got a few problems – the first is that you’re trying to compare the raw object to the button value: (employee == buttonValue). Instead you need to compare to whatever you’re looking for, ie for language employee.language == buttonValue

    The second is that if any object in the array doesn’t match it’ll append no results. This can be resolved by having a flag to indicate if a result was found or not – outside of the .each loop make the flag and set to false – if a result is found set flag to true. After the .each loop check to see if a result was set – if not, display no result.

    Here’s a working solution.

    $('button').click(function(){
        var but = this;
        var results = false;
        $.each(employees, function(index, employee){
            if(employee.language == but.value)
            {
                results = true;
                $('#resultsView').append('<div class="searchResults">' + employee.firstName + employee.lastName + '<br />' + employee.language + '<br />' + employee.department + employee.position + '<br />' + employee.skill + '</div>');
            }
        });
        if(!results)
        {
            $('#resultsView').append('<div id="resultsView" class="noResult">No results found</div>');
        }
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have read some of the questions and answers here, but it none match
I have read multiple articles about why singletons are bad. I know it has
I have read few articles about table partioning but still I am bit confused
I have read few good articles about NHibernate localization but nothing seems to fit
I have read a few good articles about coding a socket server but thought
Thanks for reading. I have done a search, read multiple posts (lost count) and
If we have a website with multiple images and videos, I've read that it's
I have read a lot of topic here and people tend to store IP
Having read the claim multiple times in articles - I want to add this
So I've read a bunch of articles, both here on SO, and elsewhere, on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.