In ES5 environment, you could use Array#some, if you expect only one result.
var data = { "main": [{ "id": "123", "name": "name 1" }, { "id": "234", "name": "name 2" }] },
result;
data.main.some(function (a) {
if (a.id === '234') {
result = a;
return true;
}
});
console.log(result);
When you expect more than one result set, you may better use Array#filter
var data = { "main": [{ "id": "123", "name": "name 1" }, { "id": "234", "name": "name 2a" }, { "id": "234", "name": "name 2" }] },
result = data.main.filter(function (a) {
return a.id === '234';
});
console.log(result);
In ES6 environment, you could use Array#find for the first found element, but if there are more to find, then use Array#filter.
var data = { "main": [{ "id": "123", "name": "name 1" }, { "id": "234", "name": "name 2" }] },
result = data.main.find(a => a.id === '234');
console.log(result);