JSFiddle - React, Tailwind, and code Playground
by gchoken
JavaScript
var name = 'contact[1]';
// This will increment the numeric array index for cloned field names
if (name) {
var matches = name.match(/\[([0-9]+)\]/);
if (matches && matches.length >= 1) {
var st = name;
name = [].map.call(st, function (s, i) {
console.log(s);
return (!isNaN(+s) && st[i - 1] === '[' && st[i + 1] === ']') ? i : s;
}).join('');
console.log(name);
}
}