i have a problem with adding new values to existing objects when they have equal values. My point is to add new value to existing object, but when object value is equal with other postion object value then they have to get same new value, but otherwise object get just a value.
var array = [
{"first": [10, 20], "last": [40, 50]},
{"first": [60, 22], "last": [10, 20]},
{"first": [40, 50], "last": [60, 22]},
{"first": [40, 50], "last": [44, 33]}
];
for (var i = 0; i < (array.length); i++) {
for (var j = 0; j < (array.length); j++) {
if (array[i].first[0] == array[j].last[0] && array[i].first[1] == array[j].last[1]) {
/* I'm not sure, what to do here
but I want to add same values to equal objects
*/
array[i].first.push(i);
array[j].first.push(i);
}
}
}
I want to get that output:
var array = [
{"first": [10, 20, 1], "last": [40, 50, 2]},
{"first": [60, 22, 3], "last": [10, 20, 1]},
{"first": [40, 50, 2], "last": [60, 22, 3]},
{"first": [40, 50, 2], "last": [44, 33, 4]}
];
last number are new values,but im not sure how do get that output, i think maybe one way is to save equal objects positions and then doing something with them , but im not sure, maybe can somebody give me advice?