gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 14:32:28 25 4
gpt4 key购买 nike

假设我有如下数组

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/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com