I want to execute a function for all "on" rows with same userId from this array:
productIds, userIds, status
[ 'com--test,LFutx9mQbTTyRo4A9Re5ksjdnfsI4cKN4q2,on',
'com--test,LFutx9mQbTTyRo4A9Re5ksjdnfsI4cKN4q2,off',
'com--fxtrimester,LFutx9mQbTTyRoldksfns4A9Re5I4cKN4q2,on',
'com--fxyear,LFutx9mQbTTyRoldksfns4A9Re5I4cKN4q2,on'
'com--fxtrimester,LFutx9mQbTTyRoldksfns4A9Re5I4cKN4q2,off',
'com--fxyear,LFutx9mQbTTyRoldksfns4A9Re5I4cKN4q2,off',
'com--fxyear,SEzlksdfMpW3FxkSbzL7eo5MmqkPczCl2,on',
'com--fxtrimester,SEzlksdfMpW3FxkSbzL7eo5MmqkPczCl2,on' ]
So for this
'com--fxtrimester,SEzlksdfMpW3FxkSbzL7eo5MmqkPczCl2,on',
'com--fxyear,SEzlksdfMpW3FxkSbzL7eo5MmqkPczCl2,on',
or this:
'com--fxtrimester,LFutx9mQbTTyRoldksfns4A9Re5I4cKN4q2,on',
'com--fxyear,LFutx9mQbTTyRoldksfns4A9Re5I4cKN4q2,on'
Execute something like:
`setProductsToUser(productIds,userId)`
-- First parameter is array ([com--fxtrimester, com--fxyear]) and the second is a userId (string) (SEzlksdfMpW3FxkSbzL7eo5MmqkPczCl2)
any idea? I try to split the object into three objects and iterate for every key but it is so mucho code and the iteration for each userId is not working. The second for loop compares the same values even when I am selecting a different key for the array. Edit: also I need to send just one request per userId
Why the for loops are not workinggg!!
var finals= 0
//the array of the question is this "unique" and what it does is delete the duplicated values just here
var unique = products.filter(function(elem, index, self) {
return index == self.indexOf(elem);
})
console.log(unique)
unique.forEach(function(data) {
//spliting the array and when it finish iterate the arrays
finals++
var dataArray = data.split(',');
productIds.push(dataArray[0]);
userIds.push(dataArray[1]);
status.push(dataArray[2]);
if(finals == unique.length) {
console.log("userIDs "+userIds.length)
for (var h = 0; h <= userIds.length ; h++) {
if( status[h] == "on") {
for (var k = 0; k <= userIds.length ; k++) {
if(status[k] === "on" && userIds[k] == userIds[h] && productIds[h] == productIds[k] ) {
productsOn.push(productIds[k]);
userId = userIds[h];
}
}
//setProductsToUser(productsOn,userId)
}
}
}
});