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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T03:09:00+00:00 2026-05-26T03:09:00+00:00

Array.prototype.testi = function() {console.log(‘hep’);} var b = new Array(); b.push(1, 5, ‘b’, ‘c’); for

  • 0
Array.prototype.testi = function() {console.log('hep');}
var b = new Array();

b.push(1, 5, 'b', 'c');

for (var i in b) {
    console.log(b[i]);
}

This will log (in chrome)

1
2
b
c
function () {console.log('hep');}

Or live example in http://jsfiddle.net/marqs/6VVka/1/

My question is, why is the function shown in the listing, even though it’s given to the array prototype?

This has implications for extending browser functionalities that aren’t used (for ex. IE extended Array.filter will behave differently if array in is used etc).

Edit:
to clarify, I have no access to the code that does the for-in loop, as it’s an external library. Thus the formulation of the question, more about “why is this so” than how to fix 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-05-26T03:09:00+00:00Added an answer on May 26, 2026 at 3:09 am

    JavaScript Objects are a collection of properties. Inside these properties, there are properties that describe the properties. The main one you are looking at here is the [[Enumerable]] property, which is a meta-property extended to most of the default objects in JavaScript, such as Array and Object. ECMAScript 5 defines a method for adding non-[[Enumerable]] objects, but that may not be widely supported in browsers.

    One way to prevent enumerating over object properties you don’t want is to check if the object property has an internal property method called [[GetOwnProperty]]. This ensures the property was directly invoked on the object and NOT inherited somewhere along the prototype chain.

    var arr = ['a','b','c'], indexes = [];
    Array.prototype.each = function() {/*blah*/}; 
    
    for (var index in arr) {
        if (arr.hasOwnProperty(index)) {
        indexes.push(index);
        }
    }
    
    indexes; //["0", "1", "2"]
    

    Source: http://javascriptweblog.wordpress.com/2011/01/04/exploring-javascript-for-in-loops/

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

Sidebar

Related Questions

var objs = new Array(); function Foo(a) { this.a = a $(#test).append($(<button></button>).html(click).click(this.bar)); } Foo.prototype.bar
From: http://ejohn.org/apps/learn/#2 Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object =
Array.prototype.push8 = function (num) { this.push(num & 0xFF); }; Array.prototype.push16 = function (num) {
Function.prototype.bind = function(){ var fn = this, args = Array.prototype.slice.call(arguments), object = args.shift(); return
TL;DR: Adding any non-built-in functions to Array.prototype AND Function.prototype will cause the IE8 native
I thought this would be as easy as: if(typeof(Array.push) == 'undefined'){ //not defined, prototype
var down=function(a,b){alert(a)} Array.prototype.sort.call(table.tBodies[0].childNodes,down) Array.prototype.sort.call([0,1,2,3],down) Why do I not get alerts from the first sort
function Foo(){ } Foo.prototype={ method1:function(o){ console.log(o); } ,shorthand:function(){ if(!arguments.length || typeof arguments[0]=='undefined') { arguments[0]={};
I create an array search prototype Array.prototype.searchRE = function(searchStr) { var returnArray = false;
I found this method: Array.prototype.compare = function(arr) { if (this.length != arr.length) return false;

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.