var nodeLists = ["/data1/chenleileitest/1T/"]
如何快速将上述数组变换成如下的格式
["/data1/","/data1/chenleileitest/","/data1/chenleileitest/1T/"]
我想的是使用split对数组元素划分,然后再拼接,但这是对数组元素只有一个的情况比较好处理,如果数组的元素比较多的情况呢?
["/data1/chenleileitest/1T/","/boot/gurb2/themes/system/","/sys/dev/block/8:16/device/"]
将其转换成如下形式
["/data1/","/data1/chenleileitest/","/data1/chenleileitest/1T/","/boot/","/boot/gurb2/","/boot/gurb2/themes/","/boot/gurb2/themes/system/","/sys/","/sys/dev/","/sys/dev/block/","/sys/dev/block/8:16/","/sys/dev/block/8:16/device/",]
var nodeList = [];
nodeList = nodeLists.map(function(value, index, array) {
return '/'+value
}).filter(function(item,index, array){
return item !== '/'
})
得到的结果是:
["/data1", "/chenleileitest", "/1T"]
实现想要的结果需要,第一的加上第二个,第一个加第二个加第三个,组成最终想要的结果
Cats萌萌
相关分类