假设我有如下数组
myArray 保存两个值
0: <maintenanceshortterm type="System.Int32">1111</maintenanceshortterm>
1: <maintenanceshortterm type="System.Int32">1234</maintenanceshortterm>
我想仅使用 jQuery/JS 检索值 1111 和 1234。
请帮助我如何检索这样的值?您可能会猜到数组中的值实际上是通过 xml 来的。
最佳答案
假设每个项目只是一个 maintenanceshortterm
并且没有嵌套结构或任何东西,一个简单的正则表达式就可以做到:
const arr = [
'<maintenanceshortterm type="System.Int32">1111</maintenanceshortterm>',
'<maintenanceshortterm type="System.Int32">1234</maintenanceshortterm>'
];
console.log(
arr.map((str) => str.match(/>([^<]+)</)[1])
);
关于javascript - 如何从数组中检索数据(数组内有 xml 数据)?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50938640/