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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 8, 20262026-06-08T20:10:09+00:00 2026-06-08T20:10:09+00:00

I have extended Array prototype: if(typeof Array.prototype.filter === ‘undefined’) Array.prototype.filter = function(fun /*, thisp*/){

  • 0

I have extended Array prototype:

if(typeof Array.prototype.filter === 'undefined') Array.prototype.filter = function(fun /*, thisp*/){
  var len = this.length;
  if(typeof fun != "function") throw new TypeError();

  var res = [], thisp = arguments[1];

  for(var i=0;i<len;i++){
    if(i in this){
      var val = this[i]; // in case fun mutates this
      if(fun.call(thisp, val, i, this)) res.push(val);
    }
  }

  return res;
};

For example I have created array:

var A = [ 1, 2, 3, 4, 5 ];

Then I added extra properties to it, that I will use:

A.creator = 'Rustam';
A.created = new Date();

If I will use for-in loop, and browser has not built-in support for Array.filter, it will go through A.filter.

I know this way:

for(var p in A) {
  if (!A.hasOwnProperty(p)) continue
  console.log(p)
};

Is there a way to make A.filter hidden in for-in without using hasOwnProperty?


UPDATE to answer. Browser support:

  • IE9+
  • FF4+
  • Chrome
  • Opera 11.6+
  • Safari 5+
  • 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-08T20:10:10+00:00Added an answer on June 8, 2026 at 8:10 pm

    To define a property which does not show up in loops, use Object.defineProperty:

    Object.defineProperty(Array.prototype, 'filter', {value:'XYZ'});
    

    This extends Array.prototype with a property called filter with default property descriptors, including enumerable: false, which causes the property to not show up in for( .. in ..) loops.

    References

    • Object.defineProperty at MDN
    • Object.defineProperty at MSDN

    PS: Will not work on older browsers I don’t have the browser compatibility matrix for this API.

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

Sidebar

Related Questions

Just wonder. I have extended javascript Array object using its prototype as follows: <html>
Array.prototype.testi = function() {console.log('hep');} var b = new Array(); b.push(1, 5, 'b', 'c'); for
I have declared my two dimensional array like this. But getting an error due
I have the following function to convert a byte array of pixels into an
I have a object that is extended from arraycollection. This object has to access
I have a standard javascript object whose prototype is extended with a .start() method
I have extended LinearLayout (vertical) to create a custom compound component. This in turn
say I have an array like this: [Option] => Array ( [0] => Array
I have this error, Fatal error: Call to undefined method CI_Input::file() in D:\xampp\htdocs\application\controllers\page.php on
I have extended SimpleCursorAdapter and am running into a weird issue with bindView, which

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.