Skip to content

Instantly share code, notes, and snippets.

@cian6390
cian6390 / getUrlVars.js
Last active May 21, 2016 14:11
JavaScript get url parameter with decode
function getUrlVars() {
var url = decodeURIComponent(window.location.href);
var vars = {};
var hashes = url.split("?")[1];
var hash = hashes.split('&');
for (var i = 0; i < hash.length; i++) {
params = hash[i].split("=");
vars[params[0]] = params[1];
@cian6390
cian6390 / flatObj.js
Last active May 21, 2016 14:11
JavaScript Object Flatten
function flatObj(obj) {
if (!obj || typeof obj !== 'object' || obj instanceof Array) {
throw new TypeError('flatObj() arguments need be object');
}
var result = {};
for (var x in obj) {
if (obj[x] && typeof obj[x] === 'object') {
for (var y in obj[x]) {
result[x + '_' + y] = obj[x][y];
}