IT Community - Software Programming, Web Development and Technical Support

filter element in Javascript array

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 = ...


Go Back   IT Community - Software Programming, Web Development and Technical Support > Web Development > HTML, CSS and Javascript Coding Techniques

Register FAQ Members List Calendar Mark Forums Read
  #1 (permalink)  
Old 02-08-2008, 11:05 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default filter element in Javascript array

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Sponsored Links
  #2 (permalink)  
Old 02-08-2008, 11:16 PM
Falcon Falcon is offline
D-Web Analyst
 
Join Date: Nov 2007
Location: Chennai
Posts: 289
Falcon is on a distinguished road
Default Re: filter element in Javascript array

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #3 (permalink)  
Old 02-08-2008, 11:22 PM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: filter element in Javascript array

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #4 (permalink)  
Old 02-09-2008, 12:21 AM
Falcon Falcon is offline
D-Web Analyst
 
Join Date: Nov 2007
Location: Chennai
Posts: 289
Falcon is on a distinguished road
Default Re: filter element in Javascript array

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
  #5 (permalink)  
Old 02-11-2008, 07:25 AM
Jeyaseelansarc Jeyaseelansarc is offline
D-Web Genius
 
Join Date: Mar 2007
Location: Chennai
Posts: 1,162
Jeyaseelansarc is on a distinguished road
Send a message via AIM to Jeyaseelansarc
Default Re: filter element in Javascript array

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
Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


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


All times are GMT -7. The time now is 10:04 AM.


Copyright ©2004 - 2007, DiscussWeb. All Rights Reserved.

SEO by vBSEO 3.0.0