删除数组中的sting内容

时间:2015-10-07 13:45:21

标签: javascript arrays

我有一个像这样的Javascript数组:

VirtualMachineByPhysicalMachine::GROUP-USER-DEV
,DRS-shou-2/domain-b/shou18lcorevc::PM-GROUP-DRS-domain-b/core
,DRS-SQLCluster/domain-c/10.128::PM-GROUP-DRS-domain-c/10.128
,DRS-WC2012test/domain-c/10.128::PM-GROUP-DRS-domain-c/10.129
,DRS-RAC/domain-c/10.128::PM-GROUP-DRS-domain-c/10.130
,DRS-RHELCluster/domain-c/10.128::PM-GROUP-DRS-domain-c/10.131
,VirtualMachineByPhysicalMachine::GROUP-USER-PROD
,DRS-WC2008test/domain-c/10.128::PM-GROUP-DRS-domain-c/10.132
,DRS-SybaseCluster/domain-c/10.128::PM-GROUP-DRS-domain-c/10.133

我想格式化数组如下:

GROUP-USER-DEV
, PM-GROUP-DRS-domain-b/core
, PM-GROUP-DRS-domain-c/10.128
, PM-GROUP-DRS-domain-c/10.129
, PM-GROUP-DRS-domain-c/10.130
, PM-GROUP-DRS-domain-c/10.131
, GROUP-USER-PROD
, PM-GROUP-DRS-domain-c/10.132
, PM-GROUP-DRS-domain-c/10.133

2 个答案:

答案 0 :(得分:0)

你能试试吗?

var arr =['VirtualMachineByPhysicalMachine::GROUP-USER-DEV'
,'DRS-shou-2/domain-b/shou18lcorevc::PM-GROUP-DRS-domain-b/core'
,'DRS-SQLCluster/domain-c/10.128::PM-GROUP-DRS-domain-c/10.128'
,'DRS-WC2012test/domain-c/10.128::PM-GROUP-DRS-domain-c/10.129'
,'DRS-RAC/domain-c/10.128::PM-GROUP-DRS-domain-c/10.130'
,'DRS-RHELCluster/domain-c/10.128::PM-GROUP-DRS-domain-c/10.131'
,'VirtualMachineByPhysicalMachine::GROUP-USER-PROD'
,'DRS-WC2008test/domain-c/10.128::PM-GROUP-DRS-domain-c/10.132'
,'DRS-SybaseCluster/domain-c/10.128::PM-GROUP-DRS-domain-c/10.133'
]

var newArr= arr.map(function (anObj){
    return anObj.split("::")[1];

});

console.log(newArr);

答案 1 :(得分:0)

你可能能够做一些拆分。

类似的东西:

for (var i = 0; i < arr.length; i++) {
    arr[i] = arr[i].split("::")[1];
}