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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:27:29+00:00 2026-05-23T15:27:29+00:00

Possible Duplicate: Javascript – array.contains(obj) What’s wrong with this: var zipCodes =([‘90001′,’90002′,’90003’]); Test if

  • 0

Possible Duplicate:
Javascript – array.contains(obj)

What’s wrong with this:

var zipCodes =(['90001','90002','90003']);

Test if the value exists in the array zipCodes

if('90001' in zipCodes) {
  alert('True');
};
  • 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-05-23T15:27:29+00:00Added an answer on May 23, 2026 at 3:27 pm

    The in operator looks at property names, not values.

    Because it’s an Array, the property names will be the indices of the Array.

    If you’re only supporting a modern environment, you could use Array.prototype.indexOf().

    if(zipCodes.indexOf('90001') > -1) {
    

    If you need to support environments that don’t have .indexOf(), you could implement the MDN fix.

    if (!Array.prototype.indexOf) {
        Array.prototype.indexOf = function (searchElement /*, fromIndex */ ) {
            "use strict";
    
            if (this === void 0 || this === null) throw new TypeError();
    
            var t = Object(this);
            var len = t.length >>> 0;
            if (len === 0) return -1;
    
            var n = 0;
            if (arguments.length > 0) {
                n = Number(arguments[1]);
                if (n !== n) // shortcut for verifying if it's NaN
                n = 0;
                else if (n !== 0 && n !== (1 / 0) && n !== -(1 / 0)) n = (n > 0 || -1) * Math.floor(Math.abs(n));
            }
    
            if (n >= len) return -1;
    
            var k = n >= 0 ? n : Math.max(len - Math.abs(n), 0);
    
            for (; k < len; k++) {
                if (k in t && t[k] === searchElement) return k;
            }
            return -1;
        };
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Possible Duplicate: Javascript swap array elements I have a array like this: this.myArray =
Possible Duplicate: JavaScript: Getting random value from an array var numbers = new Array('1','2','4','5','6','7','8','9','10');
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} What's the
Possible Duplicate: Javascript regex returning true.. then false.. then true.. etc var r =
Possible Duplicate: JavaScript: var functionName = function() {} vs function functionName() {} Suppose we
Possible Duplicate: Javascript: var functionName = function() {} vs function functionName() {} Way 1:
Possible Duplicate: JavaScript scope and closure What is this for? (function(){ //The code to
Possible Duplicate: Is JavaScript’s math broken? This seems really stupid, but when running this,
Possible Duplicate: Javascript: is using 'var' to declare variables optional? When creating variables in
Possible Duplicate: JavaScript function aliasing doesn't seem to work Why doesn't this work? function

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.