A
A
Amir Gafurov2014-03-17 12:34:07
JavaScript
Amir Gafurov, 2014-03-17 12:34:07

How to properly implement json search?

There is a JSON array:

[
    {
        "id": 1,
        "collection_id": 5,
        "code": "triniti_001",
        "name": "Тринити 001",
        "variant" : [
            {"wood" : 1, "glass" : 0, "form" : 1},
            {"wood" : 2, "glass" : 0, "form" : 1},
            {"wood" : 3, "glass" : 0, "form" : 1}
        ]
    },
    {
        "id": 2,
        "collection_id": 5,
        "code": "triniti_002",
        "name": "Тринити 002"
    },
    {
        "id": 3,
        "collection_id": 5,
        "code": "triniti_003",
        "name": "Тринити 003"
    }
]


How to choose

{
        "id": 1,
        "collection_id": 5,
        "code": "triniti_001",
        "name": "Тринити 001",
        "variant" : [
            {"wood" : 1, "glass" : 0, "form" : 1},
            {"wood" : 2, "glass" : 0, "form" : 1},
            {"wood" : 3, "glass" : 0, "form" : 1}
        ]
    },

by, for example, "code": "triniti_001" ?

Answer the question

In order to leave comments, you need to log in

2 answer(s)
K
Kuzzy, 2014-03-17
@amir73911

Underscore is good for things like this jsfiddle.net/MpR4S

R
Ruslan Lopatin, 2014-03-17
@lorus

No underscore needed here. Everything is beautifully written in pure JavaScript. A simple loop or Array.some() if you want functionality.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question