function convertToQuery(obj, prefix) {
	let queryParts = []

	for (param in obj) {
		if (obj.hasOwnProperty(param)) {
			let key = prefix ? prefix + "[]" : param;
			let value = obj[param];

			queryParts.push(
				(value !== null && typeof value === "object") ?
				convertToQuery(value, key) :
					key + "=" + value
			);
		}
	}

	return queryParts.join("&");
}
Credit goes to https://stackoverflow.com/a/1714899