Skip to content

How to find a item based on a key

Mathias Rangel Wulff edited this page Jun 13, 2015 · 4 revisions

How to find a item based on a Key?

Source: StackOverflow.com

Question

Given a JSON object like:

    var data = {items: [
        {value: "21", name: "Mick Jagger"},
        {value: "43", name: "Johnny Storm"},
        {value: "46", name: "Richard Hatch"},
        {value: "54", name: "Kelly Slater"},
        {value: "55", name: "Rudy Hamilton"},
        {value: "79", name: "Michael Jordan"}
    ]};

How can I do something like this:

    datagood = data.where(value == 55)

Is something like that possible with JS?

Answer

AlaSQL library can perform more complex queries with "old good" SQL:

    var res = alasql('SELECT * FROM ? WHERE value = 55',[data]);

Try this example in jsFiddle

Clone this wiki locally