Created
March 27, 2012 14:20
-
-
Save akoimeexx/2216292 to your computer and use it in GitHub Desktop.
Javascript Datatype functions
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* JavaScript datatype functions | |
* adds additional functions to datatypes that are generally considered | |
* essential in other programming languages | |
* | |
* written by Akoi Meexx on April 13th, 2010 | |
*/ | |
/** | |
* String functions | |
*/ | |
// Add string trimming | |
String.prototype.trim = function () | |
{ | |
return this.replace(/^\s*/, "").replace(/\s*$/, ""); | |
} | |
/** | |
* Array functions | |
*/ | |
// Clarify adding an index item to an array | |
Array.prototype.add = function (value, index) | |
{ | |
// if no index is passed in(undefined) set it to the array length | |
if(index === undefined) | |
{ | |
index = this.length; | |
} | |
return this.splice(index, 0, value); | |
} | |
// Clarify removal of an index item from an array | |
Array.prototype.remove = function (index) | |
{ | |
return this.splice(index, 1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment