devxlogo

Extend the Array JavaScript Object with Your own Functions

Extend the Array JavaScript Object with Your own Functions

The JavaScript Array intrinsic object (and others) can be extended to include user-defined functions in the object definition. These extensions can be placed in a .js file and included in all pages to create a common library.
In the example below, the Array object has been extended with a contains function that checks the array for the specified string. The caseSensitive global variable is used to indicate case comparison. All instantiated arrays will now be able to use the .contains method.

 Array.contains

size=3>

devxblackblue

About Our Editorial Process

At DevX, we’re dedicated to tech entrepreneurship. Our team closely follows industry shifts, new products, AI breakthroughs, technology trends, and funding announcements. Articles undergo thorough editing to ensure accuracy and clarity, reflecting DevX’s style and supporting entrepreneurs in the tech sphere.

See our full editorial policy.

About Our Journalist