I have a string lists/listA/listB/listC/...
.
Please tell me how I can split the string to this view and write the result to an array:
JavaScript
x
9
1
[
2
{0: lists},
3
{1: lists/listA},
4
{2: lists/listA/listB},
5
{3: lists/listA/listB/listC},
6
{4: lists/listA/listB/listC/ },
7
{/...} :
8
]
9
Advertisement
Answer
Here is the solution:
JavaScript
1
6
1
let splitedArray = 'lists/listA/listB/listC/...'.split('/');
2
let string = '';
3
const result = splitedArray.map((item, index) => {
4
return {[index]: string = string + (!index ? item : `/${item}`)};
5
});
6
console.log('result', result)