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

  • SEARCH
  • Home
  • 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 8740043
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:03:40+00:00 2026-06-13T11:03:40+00:00

I have an array of objects in javascript. The objects contain some properties and

  • 0

I have an array of objects in javascript. The objects contain some properties and look something like this :

  { "Name" : "blabla", "Id": "1" }

Now I have a function which accepts a single parameter that will be the Name property value of the object. The function looks somethings like this :

     function CheckForExistance(array, name){
       var exist = false;

       $.each(array, function(index, value){
          if(value.Name == name)
          {
             exist = true;
             return false;
          }
       });
       return exist;
     }

I want to know if there is a better way to do this ?

  • 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-13T11:03:41+00:00Added an answer on June 13, 2026 at 11:03 am

    You can use $.grep() to filter down the array to a match, and return a comparison of the .length.

     function CheckForExistance(array, name){
         return $.grep(array, function(obj) {
             return obj.Name == name;
         }).length > 0;
     }
    

    Or native methods are a little nicer IMO, but you’ll need a shim for old browsers.

    function CheckForExistance(array, name){
        return array.some(function(obj) {
            return obj.Name == name;
        });
    }
    

    This one uses Array.prototype.some, and will exit as soon as a truthy return value is given, and will then return true. If no truthy return is found, then it’ll return false.


    FWIW, you can make your function a little more robust by providing a dynamic property name as well.

    function CheckForExistance(array, prop, val){
        return array.some(function(obj) {
            return obj[prop] == val;
        });
    }
    

    Then use it to check any property value.

    var found = CheckForExistance(myArray, "Name", "blabla");
    

    Or another approach would be to make a function factory that creates functions to be used with iterators.

    function havePropValue(prop, value) {
        return function(obj) {
            return obj[prop] == value;
        };
    }
    

    Then we can just use .some() directly without needing the CheckForExistance function.

    var found = myArray.some(havePropValue("Name", "blabla"));
    

    Or with $.grep.

    var found = $.grep(myArray, havePropValue("Name", "blabla")).length > 0;
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a JavaScript array of objects with the same properties each, something like
I have an JavaScript object like this: id=1; name = serdar; and I have
I have a collection of objects in JavaScript like this: Object collection = new
I have an array of JavaScript objects: var objs = [ { first_nom: 'Laszlo',
When I have array of objects, when I type the name of variable in
I have an array of objects in javascript. The array is : [ {
I have a javascript object that contains a few objects that contain associative arrays.
I have a JavaScript object that looks like the following: venue = function(map, dataSet)
I have Javascript array which contains User object. I have created this array from
I have an array of objects in javascript, each of which in turn has

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.