javascript - 如何从数组中检索数据(数组内有 xml 数据)?

标签 javascript jquery arrays

假设我有如下数组

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/

相关文章:

javascript - 将一个数分解为 100 的因数并保留余数

jquery - 如何使用 jVectorMap 从 onRegionClick 回调内的 map 数组中获取州名称?

javascript - 如何使用剑道文件上传异步方法获得响应?

javascript - 如何根据页面上不同对象的位置在 Javascript/Mootools 中定位箭头

javascript - 为什么 Bootstrap 导航栏中没有跟踪我的链接

javascript - 更改 contenteditable 后恢复光标位置

javascript - 为什么 IF 语句不起作用?

javascript - 未选中复选框时从数组中删除元素

php - 将mysql数据插入div

c - 将多维数组传递给函数