I've got an array with multiple objects in it with the following information:
string ProductDescription/Name
int Amount
I want to create an new array that combines the Amount of the same productdescriptions. Example: the 1st array contains: Product X 50, Product X 80 and Product X 140.
My new array should be Product X 270.
Now I found something about checking if a value is already in an array: https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Global_Objects/Array/some
But I want something that will check the ProductDescription
, instead of the object.
So I took the same function:
function checkAvailability(arr, val)
{
return arr.some(function(arrVal)
{
return val === arrVal;
});
}
And I try it like this:
var found = checkAvailability(arrayProduct['Productomschrijving'], javascript_array[i]['Productomschrijving']);
But it gives an error...
Uncaught TypeError: Cannot read property 'some' of undefined
When I do it like this:
var found = checkAvailability(arrayProduct, javascript_array[i]['Productomschrijving']);
It's always false. Kinda normal since it's comparing a string with objects.
So how can I get this solved that my some
function is checking on the property of an object instead of the complete object?