Florian Mittlböck Florian Mittlböck - 1 year ago 69
jQuery Question

How do I get the book title with a specific id using linqjs

I have a JavaScript array with objects in it which contain an id, book title usw, I need to search it and get the title with a given id preferable with linqjs.


"213-46-8915" : id

"The Busy Executive's Database Guid" : Title

var books = [];
books.push(["213-46-8915" , "The Busy Executive's Database Guid",19.9900,2]);
books.push(["211-44-2314" , "The Busy Executive's Database Guid",14.4100,5]);

My try:

var filtered = Enumerable
.Where(function (x) {return x.contains(id);})
.Select(function (x) {return x;})

Answer Source

According to the documentation, you have to call JSLINQ(array) first.

So, for your example. This should work. Also, I converted your array to an object

var books = [];
    id: "213-46-8915",
    title: "The Busy Executive's Database Guid",
    price: 19.9900,
    quantity: 2

var filtered = JSLINQ(books)
               .Where(function(item) { return item.id == "213-46-8915"; })
               .Select(function(item) { return item; });

console.log(filtered.id); //213-46-8915 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download