javascript : Array.distinct()
javascript : Array.distinct()
Target:
Applicable with Array Data Type.
Description :
It remove duplicate items from array and create new array having distinct values/objects. It is an extension method of array object defined in array prototype.
Note: logic behind it is create a new array and push only that items which are not contains in array.
Syntax:
[].distinct()
return new array having unique and distinct values.
Usase:
- [1,2,5,8,4,2,6,3,5,1,3,4,5].distinct()
It return new array [1, 2, 5, 8, 4, 6, 3] - "Welcome in myjs tutorials".toArray().distinct()
It return new array ["W", "e", "l", "c", "o", "m", " ", "i", "n", "y", "j", "s", "t", "u", "r", "a"] - "Welcome in myjs tutorials".toCharCodeArray().distinct()
It return new array [{"char":"W","code":87},{"char":"e","code":101},{"char":"l","code":108},{"char":"c","code":99},{"char":"o","code":111},{"char":"m","code":109},{"char":" ","code":32},{"char":"i","code":105},{"char":"n","code":110},{"char":"y","code":121},{"char":"j","code":106},{"char":"s","code":115},{"char":"t","code":116},{"char":"u","code":117},{"char":"r","code":114},{"char":"a","code":97}]
Download MYJS.js
MyJs is a collection of java script extension methods that enhances the JavaScript objects, class object, DOM element, domElementsCollections, Date, String, Number and other data type.
Include in you project landing page (master page) and it will extends your DOM and JavaScript Objects.
Comments
Post a Comment