JavaScript function prototype __ function

Source: Internet
Author: User

Remove spaces on both sides of the string String.prototype.trim = function () {    var re =/(^\s*) | (
\s*) $/g;


    return This.replace (Re, "");} Deletes an element in an array Array.prototype.remove = function (i) {    var o = this[i];     for (var j = i; j < th Is.length-1;  J + +) {        THIS[J] = this[j + 1];//starting from the first element, to the penultimate element, replacing the previous element with the following elements    }    
--this.length;      return o; //Determine if an array has the same element Array.prototype.search = function (o) {    for (var i = 0; i < this.length i + +) {& nbsp 
      if (this[i] = O) {            return i;        }
   }     return-1;
//Below is the test var str = "This is test string  ";
Console.log (str);
Console.log (Str.trim ());




Console.log (str);
var arr = [1, 2, 3, 4];
Console.log (arr.length);
Console.log (Arr.remove (2));


Console.log (arr);
var arr = [1, 2, 3, 4]; Console.log (arr.searCH (5));

 Console.log (Arr.search (3));

Reference: http://security.ctocio.com.cn/tips/337/7716837_3.shtml

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.