I have string like that:
const test = '1.1.1.2';
from this string I need create nested array:
{
items :[{
name: '1',
items: [{
name:'1.1',
items:[{
name: '1.1.1',
items: [{
name: '1.1.1.2'
}]
}]
}]
}]
}
how can I that? thanks for any help
This is the attempted code
function foo(test, items2, item, index) {
if (test.hasOwnProperty('items') && test.items instanceof Array && test.items.length === 0) {
var varoo = test.items.push({
name: items2[index],
items: []
});
foo(varoo, items2, item, index)
} else {
test = {
name: items2[index],
items: []
};
}
}