I have an array filled with objects.
The array is built programatically, with el being an element on a page and errorCode being an error code I generate based on arbitrary logic. What I'd like to do is cycle through the array and compare the object.el to see if it has any duplicates. If so, take the error message and combine it (either make that part of the object an array or just concat - I can deal with that) with the other error codes.Code:var myArray = [{'el' : el, 'errorCode' : errorCode }, {'el' : el, 'errorCode' : errorCode }, {'el' : el, 'errorCode' : errorCode }];
Something to this effect:
I know prototype has things like .any, .collect, etc., but I am stumped as to how I can do this.Code:myArray.each(function(n){ n.el; n.errorCode; //I know that code does nothing, but that's the way I access the object //just giving example.... });
My whole goal is to make sure I only have unique elements in my array and have the errorcodes be an array or a - separated string.
....so the end result will be something to this effect:
again, coming from:Code:myNewArray = [{'el' : uniqueObject, 'errorCodes' : ['This is wrong.','That is wrong.', 'I love oranges.'] }, {'el' : el2, 'errorCode' : 'This element is ugly!'}];
I hope this makes sense.....Code:var myArray = [{'el' : el1, 'errorCode' : 'This is wrong.' }, {'el' : el1, 'errorCode' : 'That is wrong.'}, {'el1' : el, 'errorCode' : 'I love oranges.'}, {'el' : el2, 'errorCode' : 'This element is ugly!'}];


Reply With Quote
Bookmarks