0

Imagine I have array as below

myArray holds two values as

0: <maintenanceshortterm type="System.Int32">1111</maintenanceshortterm>
1: <maintenanceshortterm type="System.Int32">1234</maintenanceshortterm>

I want to retrieve the values 1111 and 1234 using jQuery/JS only.

Please please help me how I can retrieve values like that? You can probably guess that that values inside the array are actually coming through xml.

0

2 Answers 2

3

Assuming each item is only a maintenanceshortterm and there's no nested structure or anything, a simple regex would do it:

const arr = [
'<maintenanceshortterm type="System.Int32">1111</maintenanceshortterm>',
'<maintenanceshortterm type="System.Int32">1234</maintenanceshortterm>'
];
console.log(
  arr.map((str) => str.match(/>([^<]+)</)[1])
);

Sign up to request clarification or add additional context in comments.

Comments

1

also you could make use of the string split mehtod

var arr = new Array('<some xml ...>1111</>', '< some xml...>1234</>');

//split the first string by '>'
var firstItem = arr[0].split(">");
//firstItem now contains "<some xml ...", "1111", ""
//want item at index 1
document.writeln(firstItem[1]);

//likewise for the second value

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.