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:
- arrayDistinct: function (arr) {
- var tempArr = {};
- for (var i = 0; i < arr.length; i++) {
- if (tempArr[arr[i] + 1]) {
- arr.splice(i, 1);
- i--;
- continue;
- }
- tempArr[arr[i] + 1] = true;
- }
- tempArr = null;
- return arr;
- },
- arrayIndexOf: function (arr, obj, iStart) {
- if (Array.prototype.indexOf) {
- return arr.indexOf(obj, (iStart || 0));
- }
- else {
- for (var i = (iStart || 0), j = arr.length; i < j; i++) {
- if (arr[i] === obj) {
- return i;
- }
- }
- return -1;
- }
- },