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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T07:24:56+00:00 2026-06-01T07:24:56+00:00

I used the code described here but now, when I do a for …

  • 0

I used the code described here but now, when I do a “for … in …” cicle, it gets the function “indexOf” as an index position of the array…

Example Code:

var the_array=new Array();                  
for (key in the_array){
    console.log(key +"  -  "+the_array[key]);
} 

This code shows this in the console:

indexOf  -  function (searchElement /*, fromIndex */ ) {  
    "use strict";  
    if (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 != Infinity && n != -Infinity) {  
            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;  
}

How could I prevent the function from appearing as a key on the array?

Btw, I know that I can use the inArray function of jquery but, in this case, I would like to use the “indexOf” function…

  • 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-01T07:24:57+00:00Added an answer on June 1, 2026 at 7:24 am

    It’s a bad idea to use for...in on arrays, for this and other reasons. See my answer here:

    Why is 'for(var item in list)' with arrays considered bad practice in JavaScript?

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This code used to return my local ip address as 192.xxx.x.xxx but now it
I used the code described here to update an excel sheet using c#. The
This code used to work but doesnt any more. i used a breakpoint, and
I used following code, but it displays only 2 digit of ISO country name.
There’s a really cool diff class hosted by Google here: http://code.google.com/p/google-diff-match-patch/ I’ve used it
Used code I found on SO to use the COM based Acrobat Reader to
I've seen (and used) code to have a link spawn a javascript action many
I have used code like this: http://msdn.microsoft.com/en-us/library/dw70f090.aspx to access database before when working in
Info - for better formatting, I used code-formatting throughout the whole posting. Hi, I
This code used to work. Then, maybe I changed something, somewhere (or if I

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.