JSFiddle - React, Tailwind, and code Playground

by Alexey Ukolov

JavaScript

values = [];
post = {
    foo: 'bar',
    baz: [0, 1, 2, 3],
};

$.each(post, function(key, value) {
    if ($.isArray(value)) {
        $.each(value, function(index, val) {
            values.push({
                type: 'hidden',
                name: key + '[]',
                value: val
            });
        });
    } else {
        values.push({
            type: 'hidden',
            name: key,
            value: value
        });
    }
});

console.log(values);