How to change the value of certain objects in the array?

There are 2 arrays of objects, objects have an id value. So: we need to go through the first array and the objects, which also are in the second array (can check id), change a specific field value to true. How is this implemented?
p.s. you can use the library
p.p.s. the decision to use only with reservations as to traverse an array
September 18th 19 at 23:55
2 answers
September 18th 19 at 23:57
Solution
var one = [{id: '1'}, {id: '2'}],
 two = [{id: '2'}, {id: '5'}],
 twoIds = [];

for ( i in two ) {
 if ( two.hasOwnProperty(i) ) {
 twoIds[two[i].id] = 1;
}
}

for (i in one) {
 if ( one.hasOwnProperty(i) ) {
 if ( twoIds[one[i].id] !== undefined ) {
 one[i].field = true;
}
}
}
: jsfiddle.net/waL3b5yk . With the addition of agree, but only in this particular case. - vincenzo commented on September 19th 19 at 00:00
The example is not correct.
one and two, you have a regular array, via in you they will not pass... just through the normal cycles. Requires prior conversion to an associative array.
if ( twoIds[one[i].id] !== undefined ) -- you can replace the if in

Addition: if there are no functions inside, and all the same type, then there is no need to use hasOwnProperty - elinore.Ebert83 commented on September 19th 19 at 00:03
you would have to agree completely... if you need crossbrowser option, but not one that works only in your version of chrome...
I recommend all re-read the application for (variable in object) - elinore.Ebert83 commented on September 19th 19 at 00:06
: With this I agree. I don't agree that you can not check hasOwnProperty. - vincenzo commented on September 19th 19 at 00:09
: if the data in the object you create yourself or get them from server in certain format, then there is no need... because you're not smart enough to put what that function deliberately or accidentally, although by accident, rather through prototypes, and only the... because it all depends on the developer, namely, what data in particular place he's going to work... - elinore.Ebert83 commented on September 19th 19 at 00:12
: That's about why. Anyone prototype will override any browser something new will come up, or, in the end, the server side decides to slightly change the format of the data =) - vincenzo commented on September 19th 19 at 00:15
in the browser nothing new that would break the functionality of the current work, will not come... about JavaScript... All new versions support the old. And prototypes to use or not, it is only the decision of the developer and in which scope are those variables that might be affected, it is also necessary to take into account, because hasOwnProperty is only light protection from the fools and no more... - elinore.Ebert83 commented on September 19th 19 at 00:18
For, let's say, the browser developers then didn't know at the time how to work with masyumi through for in.... - elinore.Ebert83 commented on September 19th 19 at 00:21
September 18th 19 at 23:59
The bypass of the first(or second) array, the construction of an object with the keys in the form of ay Dee.
When you crawl another array to hold all the comparisons and necessary action with a new object, the Changed object to push in array with 1 or beat on the keys or.... well, actually, under the right structure...
Total to make the function convert an associative array, and the second to compare objects, return a shared key. Compare using alternating bypass of both objects and the making of found keys that are in another object. The result to return...
In General, good should get rid of the arrays initially, making an associative array...

Find more questions by tags JavaScript