Publish a JavaScript tool library jutil (1)

Source: Internet
Author: User

Origin

JQuery is widely used in the work, but jQuery is no longer powerful, and some methods are useless. The previous practice was to work together. Today, I finally made up my mind to sort out some of the methods I usually use, this is the origin of jutil.

Currently, there are only 17 methods, including Array, HTML, Cookie & localStorage, Date, and String. These methods use native JS and do not rely on jQuery.

The design is easy to understand and does not need to be introduced too much. This is what I want to achieve now. Therefore, the introduction below is relatively simple, if you do not understand any part or have better suggestions, please submit them and I will optimize them.

Array-related

Jutil. arrayDistinct (Array)

Jutil. arrayIndexOf (Array, Item)

The implementation code is as follows:

 
 
  1.  arrayDistinct: function (arr) {  
  2.     var tempArr = {};  
  3.     for (var i = 0; i < arr.length; i++) {  
  4.         if (tempArr[arr[i] + 1]) {  
  5.             arr.splice(i, 1);  
  6.             i--;  
  7.             continue;  
  8.         }  
  9.         tempArr[arr[i] + 1] = true;  
  10.     }  
  11.     tempArr = null;  
  12.     return arr;  
  13. },  
  14. arrayIndexOf: function (arr, obj, iStart) {  
  15.     if (Array.prototype.indexOf) {  
  16.         return arr.indexOf(obj, (iStart || 0));  
  17.     }  
  18.     else {  
  19.         for (var i = (iStart || 0), j = arr.length; i < j; i++) {  
  20.             if (arr[i] === obj) {  
  21.                 return i;  
  22.             }  
  23.         }  
  24.         return -1;  
  25.     }  
  26. }, 


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.