so let’s say i have this JSON file:
{ "1": { "name": "some random name 1", "nickname": "some random nickname 1" }, "2": { "name": "some random name 2", "nickname": "some random nickname 2" } }
And i need function that searches by ID,("1": / "2":
is ID basically) and saves it in variable. (Using Javascript). I just don’t know how to do it.
Advertisement
Answer
Why not just standard bracket notation for this…?
var object = { "1": { "name": "some random name 1", "nickname": "some random nickname 1" }, "2": { "name": "some random name 2", "nickname": "some random nickname 2" } } console.log(object["1"]); console.log(object["2"]);