views:

51

answers:

2

Just wanted to know if I can use Linq on Javascript arrays. If not is their a 3rd party tool I can use?

+1  A: 

no, however frameworks (eg jquery) has some functions that can be used.

It's funny this morning I wanted a String.ForEachEndsWith(arr[]) method. So I created something like this:

 String.prototype.endsWith = function(str)
 { return (this.match(str + "$") == str) }

 String.prototype.forEachEndsWith = function(str_array)
 {
    var result = false;
    for(var index = 0;index < str_array.length;index++)
    {
        var current = str_array[index].toUpperCase();
        if (this.toUpperCase().endsWith(current))
        {
            result = true;
            return result;
        }
    }
    result = false;
    return result;
 }
Russell
+1  A: 

Linq is part of the .NET framework. It's not available in Javascript.

There are however similar solutions in various Javascript frameworks.

Ben S