Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Sort Array of installed plugins

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
Hello there,

I'm trying to create an sorted array with the installed plugins. I can't get the sort function to work. Here's the code I'm using:

if (navigator.plugins.length)
{
var num_of_plugins = navigator.plugins.length;
var win = window.open( "" , "Plugins" , "width=400, height=350, resizable=yes, scollbars=yes");
if (num_of_plugins > 0)
{
for (var i=0; i < num_of_plugins; i++)
{
var list_number=i+1;
win.document.write(list_number + &quot; - <B>&quot;+navigator.plugins.name+&quot;</B> (&quot; + navigator.plugins.filename + &quot;)<BR>&quot;);
}
}
}
else
{
win.document.write(&quot;<B>No Plug-ins found!</B>&quot;);
}

How can I sort this array?

Thanks in advance!

Grtx,
Phoenix
 
?? you''re just displaying it, not sorting it .... how do you want it to be sorted : which elements do you want to compare, how do you want to compare them ?
 
I'm not sorting at the moment. I want to sort by name of the plugins. I tried to do this with:

num_of_plugins.sort();

which I thought would sort the array alphabeticaly, but I got an error that the method sort is not a valid method.
 
so :
for EACH name
{
for EACH element already in the array
{
if (name < current_element)
insert name at the current_element place
}
}

of course there are far better algorithms (more efficient !!) -

 
Try this. It doesn't handle duplicate names (couldn't get it to work, anyone else??).

Good luck!

<script language=&quot;JavaScript&quot;>
if (navigator.plugins.length)
{
var num_of_plugins = navigator.plugins.length;
if (num_of_plugins > 0)
{
var c = new Array();
for (var i=0; i < num_of_plugins; i++)
{
c.push(navigator.plugins.name);
}
}
c.sort();
var y = c.length;
print(y);
for (var z=0; z<y;z++)
{
print(c[z]);
}
}
else
{
document.write(&quot;<B>No Plug-ins found!</B>&quot;);
}
//--></script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top