Skip to content

Instantly share code, notes, and snippets.

@duyet
Created October 27, 2015 16:12
Show Gist options
  • Save duyet/728ae2e2a13ee34822a9 to your computer and use it in GitHub Desktop.
Save duyet/728ae2e2a13ee34822a9 to your computer and use it in GitHub Desktop.
var data = [
{name: "otp_options[otp_option_value][5][otp]", value: "617"},
{name: "otp_options[otp_option_value][10][otpx]", value: "617"},
{name: "otp_options[otp_option_value][5][otpy]", value: "617"}
];
var data = _.map(data, function(x) {
var tmp = x.name.match(/[A-z_-]+\[[^\]]+\]\[[^\]]+\]\[([^\]]+)\]/);
var key = tmp[1] || '';
return { key: key, value: x.value };
})
data = _.object(_.pluck(data, 'key'), _.pluck(data, 'value'));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment