This is a discussion on filter element in Javascript array within the HTML, CSS and Javascript Coding Techniques forums, part of the Web Development category; Hi, i need help from you guys for filtering element in Javascript array. Here i have given the scenario Arr1 = ...
| |||||||
| Register | FAQ | Members List | Calendar | Mark Forums Read |
| |||
| Hi, i need help from you guys for filtering element in Javascript array. Here i have given the scenario Arr1 = Array(2,5,7,8) Arr2 = Array(5); I want to have new array as Array(2,7,8) which filtered by the second arrray Anybody having idea
__________________ With, J. Jeyaseelan Everything Possible |
| Sponsored Links |
| |||
| Hi Jey For array filter in the javascript use this concept it may help you var FiveplusArray=Arr1 .filter(Compare) function Compare(element, index, array) { for (i=0;i<Arr2.length;i++) { if(element != Arr2[i]) return (element) } } Regards Falcon ![]() |
| |||
| Hi Falcon, Thanks for the reply I have checked the above code in IE 7, but it not woking It worked in FF If you find anything more for this it is better
__________________ With, J. Jeyaseelan Everything Possible |
| |||
| Hi Jey You can use this phototype function for filter its will work in IE7 also. i think it will helpfull for you Array.prototype.filterArray = function(fun /*, thisp*/) { var len = this.length; if (typeof fun != "function") throw new TypeError(); var res = new Array(); var thisp = arguments[1]; for (var i = 0; i < len; i++) { if (i in this) { var val = this[i]; // in case fun mutates this if (fun.call(thisp, val, i, this)) res.push(val); } } return res; }; Filter=Arr1.filterArray (Compare) Regards Falcon ![]() |
| |||
| Hi, Thanks it is really works fine. is there any predefined functions to filter other than create this prototype functions?
__________________ With, J. Jeyaseelan Everything Possible |
![]() |
| Thread Tools | |
| Display Modes | |
| |
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Corrected line filter in C# | $enthil | C# Programming | 1 | 02-18-2008 07:12 AM |
| I am getting 'Element 'UpdatePanel' is not a known element' | poornima | ASP and ASP.NET Programming | 3 | 01-29-2008 01:09 AM |
| Arrays using Javascript - array count | raj | HTML, CSS and Javascript Coding Techniques | 3 | 12-10-2007 11:07 PM |
| Message filter applicaiton in J2ME | $enthil | J2ME | 3 | 09-20-2007 12:30 AM |
| Style filter issue in firefox | varghese | HTML, CSS and Javascript Coding Techniques | 0 | 08-08-2007 01:04 AM |