Using LinqJS find the specific value from array

Oct 9, 2014 at 9:00 AM
Edited Oct 9, 2014 at 9:10 AM
Hello,

I have one array
var strarray=["1","20","30","11","44","55"]
Using below code
var result= $.Enumberable.From(strarray)
              .Where(function(x) {return x.contains=="1"})
              .Select(function(x) {return x})
             .ToString();
it return the empty value

var result= $.Enumberable.From(strarray)
              .Where(function(x) {return x.indexOf("1")>-1})
              .Select(function(x) {return x})
             .ToString();
it return the "111";

I need to find only the array contained the number 1 only.
Kindly check
Mar 25, 2015 at 1:59 PM
Edited Mar 25, 2015 at 2:00 PM
You can do this,
   .Where(function (x) { return x == "1" || x == 1 })
   .Select(function (x) { return x })
   .FirstOrDefault();
or
   .Where(function (x) { return x == "1" || x == 1 })
   .Select(function (x) { return x })
   .FirstOrDefault("not found"); // default value or message case not found.
I tested in Chrome Console and it worked perfectly. Hope that helps.