JavaScript ObjectToQuery function return just the properties have values but i want all the properties

I am using this method in order to convert an Object to QueryString.
QueryString is required for ajax send request.

var objectToQueryString = function(a) {
  var prefix, s, add, name, r20, output;
  s = [];
  r20 = /%20/g;
  add = function(key, value) {
    // If value is a function, invoke it and return its value
    value = (typeof value == 'function') ? value() : (value == null ? "" : value);
    s[s.length] = encodeURIComponent(key) + "=" + encodeURIComponent(value);
  };
  if (a instanceof Array) {
    for (name in a) {
      add(name, a[name]);
    }
  } else {
    for (prefix in a) {
      buildParams(prefix, a[prefix], add);
    }
  }
  output = s.join("&").replace(r20, "+");
  return output;
};

function buildParams(prefix, obj, add) {
  var name, i, l, rbracket;
  rbracket = /\[\]$/;
  if (obj instanceof Array) {
    for (i = 0, l = obj.length; i < l; i++) {
      if (rbracket.test(prefix)) {
        add(prefix, obj[i]);
      } else {
        buildParams(prefix + "%" + (typeof obj[i] === "object" ? i : "") + "%", obj[i], add);
      }
    }
  } else if (typeof obj == "object") {
    // Serialize object item.
    for (name in obj) {
      buildParams(prefix + "%" + name + "%", obj[name], add);
    }
  } else {
    // Serialize scalar item.
    add(prefix, obj);
  }
}
Answer:1

I have a loading object, with boolean values for each loading. My state looks like this: state: { loading: { itemA: false, itemB: false, itemC: false } } I want to update my state ...

I have a loading object, with boolean values for each loading. My state looks like this: state: { loading: { itemA: false, itemB: false, itemC: false } } I want to update my state ...

  1. updating nested object redux
  2. updating a nested object
  3. update nested object redux
  4. redux updating nested object
  5. update nested state redux

I create a new record, this record is successfully added to the database. That's good. But the problem is that it doesn't update the list of existing records - means the push function doesn't seems to ...

I create a new record, this record is successfully added to the database. That's good. But the problem is that it doesn't update the list of existing records - means the push function doesn't seems to ...

  1. angularjs does not update view
  2. angularjs does not work in ie
  3. angularjs does not show data
  4. angularjs does not contain
  5. angularjs doesn't work
  6. angularjs doesn't work in ie
  7. angularjs doesn't update view
  8. angularjs doesn't work in ie11
  9. angularjs doesnt load
  10. angularjs doesnt render
  11. angularjs doesnt update
  12. angularjs does not bind
  13. angularjs doesnt show data
  14. angularjs does not refresh
  15. angularjs doesnt start
  16. angularjs does not display
  17. angularjs does not recognize
  18. angularjs does not show
  19. angularjs does nothing
  20. angularjs watch doesn't fire

I am trying to use the map function to create an array of the items returned from a collection. My implementation is using the forEach to iterate which works fine. However, I can't get it to work ...

I am trying to use the map function to create an array of the items returned from a collection. My implementation is using the forEach to iterate which works fine. However, I can't get it to work ...

I have a jQuery plugin that does template transformation, and an Angular directive that integrates with the plugin by calling $compile after the plugin runs on the produced DOM node: //in the link ...

I have a jQuery plugin that does template transformation, and an Angular directive that integrates with the plugin by calling $compile after the plugin runs on the produced DOM node: //in the link ...