You can use concat
to combine the arrays, and each
(from MooTools) to apply a function to each item in the combined array.
var first = [{a: "something"}, {b: "or other"}];
var second = [{d: "string"}, {e: "last object"}];
var combined = first.concat(second);
combined.each(function (item) {
item.IsPriced = 10;
});
each
is defined by MooTools, so if you're already using MooTools, you might as well use that. ECMAScript now provides a forEach
method that does the same thing, but that might not be available on all browsers. If you'd rather use the standard method, the following definition should add it to browsers that don't already support it (from the MDC article, licensed under the MIT license):
if (!Array.prototype.forEach)
{
Array.prototype.forEach = function(fun /*, thisp*/)
{
var len = this.length >>> 0;
if (typeof fun != "function")
throw new TypeError();
var thisp = arguments[1];
for (var i = 0; i < len; i++)
{
if (i in this)
fun.call(thisp, this[i], i, this);
}
};
}