Last active
August 29, 2015 14:05
-
-
Save ratiw/9f9a1f27d2af166a365a to your computer and use it in GitHub Desktop.
Combine associative array into html attributes or query string
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function makeAttributes(arr, connector, separator) { | |
var out = ''; | |
if (!connector) connector = '='; | |
if (!separator) separator = ' '; | |
for (var k in arr) { | |
out += (out === '') ? '' : separator; | |
out += k + connector + arr[k]; | |
} | |
return out; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment