I had already functioning code. Some part of the code should change two values of queryParams array:
myParam1 = 'sort_by';
myParam2 = 'sort_order';
queryParams[myParam1] = 'title';
if (queryParams[myParam2] == 'ASC') {
queryParams[myParam2] = 'DESC';
} else { //DESC or undefined
queryParams[myParam2] = 'ASC';
}
queryPairs = [];
for (var index in queryParams) {
queryPairs.push(index + "=" + queryParams[index]);
}
Unfourtunately some logic has changed and now sometimes queryParams has length 0 at the beginning of this script and then this part failes.
queryParams[myParam1] = 'title';
and
queryParams[myParam2] = 'DESC'
lines do not change queryParams.length,so the length is still 0 and the loop
for (var index in queryParams){
do not work as expected.
I have not found how to add key/value into the array.