I am trying to populate an array with the combined values of two other arrays and am trying to use a for loop to do so.
var filterTables = ["1","2","3"]
var filterValues = ["Egypt",,"Ghana"]
for (i = 0; i < filterValues.length ; i++) {
if (filterValues[i]) {
for (i = 0; i < filterValues.length ; i++) {
var filter = '{field: '+filterTables[i]+',value:'+filterValues[i]+',operator:"="},'
filterArray.filters.push(filter)
if (i===3) {
'{field: "'+filterTables[i]+'",value:"'+filterValues[i]+'",operator:"="}'
}
}
}
}
But the FOR loop isn't executing at all and I think it is because of the first IF statement that checks if there is a value in the current [i] position. Is it being used correctly? Do I need an IF statement outside of the FOR loop?
This is the desired result:
var filter = '{field: '1',value:'Egypt',operator:"="}'
var filter = '{field: '3',value:'Ghana',operator:"="}'
Aucun commentaire:
Enregistrer un commentaire