Skip to main content

create a custom prototype in JavaScript

 * JavaScript implements inheritance by using objects. Each object has an internal link to another object called its prototype.

* Prototypes are hidden objects that are used to share the properties and methods of a parent class to child classes.

Live result:- https://playcode.io/1943770

/* Find the age greater than 10 from an array of age */
var age = [10, 11, 2, 1, 20];

/*Solution 1 with .filter() function*/
let result = age.filter(function(a){
  return a>10
});
console.log('Age greater than 10 : ', result);

/*Solution 2 using custom prototype method 'showAgeGreaterThan10' */
Array.prototype.showAgeGreaterThan10 = function () {
 return(
     age.filter(function(val){
      return val>10
    })
 )
};
console.log('Custom prototype :', age.showAgeGreaterThan10());