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 8842777
In Process

The Archive Base Latest Questions

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

I tried to set an inArray with an object but it don’t works var

  • 0

I tried to set an inArray with an object but it don’t works

var test = {aa:1, bb:0}
console.log($.inArray(1,test))

I always have -1

thanks

  • 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-14T11:03:02+00:00Added an answer on June 14, 2026 at 11:03 am
    {} = object literal
    
    [] = array object
    

    $.inArray is designed to work with arrays. It will not work properly with objects as you have already figured out (it returns -1 no matter the circumstance). Speaking of objects, the syntax you used to create an object literal is ill-formed, it’s not written as { a = b } but rather as { a : b }. Here is an example:

    var test = { aa: 1, bb: 0 };
    

    I also see that you’re trying to find if a property of an object has a certain value, and not that the object has the property at all. If it were the latter case we’d use the in keyword or .hasOwnProperty function. But we’ll need to make our own function for your case. Try this:

    var inObject = function( obj, val ) {
    
        for ( var i in obj ) {
    
            if ( obj.hasOwnProperty(i) ) {
    
                if ( obj[i] === val ) return true;
    
            }
    
        }
    
        return false;
    
    };
    

    And we’ll use it like this:

    >>> var test = { aa: 1, bb: 0 };
    
    >>> inObject( test, 1 );
        true
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I tried set that, but when this, my Form still have greater height. Is
I have my root folder set to /var/www/html , but I have php program
I've tried to set the margin and border to 0,but still not working. <style
I want to achieve this using html and css: I have tried to set
I tried set fullScreenMode(false) for my app (LWUIT). But can not get Canvas. 1
I have tried (set (make-local-variable 'comment-auto-fill-only-comments) t) and also (auto-fill-mode 0) Though amazingly, neither
I tried set linewidth, but that wasn't my intention, is there anyway to shrink
I've tried Set-WSManQuickConfig command in Powershell, but it could not configure the firewall: Set-WSManQuickConfig
I tried to set the tick style to tsManual, the min and max position
I tried to set the background color of a data grid view to be

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.