(function(window) {
  var objectToParam = function(dataObject) {
    var dataArray = [];

    if (Array.isArray(dataObject)) {
      for (var i = 0; i < dataObject.length; i++) {
        for (var key in dataObject[i]) {
          if (dataObject[i][key] != null) {
            dataArray.push(
              'object[' +
                i +
                '][' +
                key +
                ']=' +
                (!Array.isArray(dataObject[i][key])
                  ? encodeURIComponent(dataObject[i][key])
                  : dataObject[i][key].map(function(item) {
                      return encodeURIComponent(item);
                    }))
            );
          }
        }
      }
    } else {
      for (var key in dataObject) {
        if (dataObject[key] != null) {
          dataArray.push(
            key +
              '=' +
              (!Array.isArray(dataObject[key])
                ? encodeURIComponent(dataObject[key])
                : dataObject[key].map(function(item) {
                    return encodeURIComponent(item);
                  }))
          );
        }
      }
    }

    return dataArray.join('&');
  };
  window.objectToParam = objectToParam;
})(window);
