{ id: 5, name: 'categories' }
<script> var str = "/categories/5"; str = str.match(/[^\/]+/g); var o = ["name","id"].reduce(function(obj, el, i) { obj[el] = i ? +str[i] : str[i]; return obj },{}); document.write(JSON.stringify(o, null, 4)) </script>