Hi Tracy
Not sure if this is "easier" but here is an alternative way (works in a server-side script):
tw.local.myVal = tw.local.myList.listToNativeArray().reduce(function (acc, cur, idx) {
return (cur.name === "Account Number" ? cur.value : acc);
});
FYI, my team uses server file(s) that hold various utilities and your requirement would be satisfied by a function like this:
Utils.findValueInList = function (list, valueProp, searchProp, searchValue) {
if (list && list.length > 0) {
for (var i = 0; i < list.length; i++) {
if (list[i][searchProp] === searchValue) {
return list[i][valueProp];
}
}
}
};
So your code would just call this function like so:
tw.local.myVal = Utils.findValueInList(tw.local.myList, "value", "name", "Account Number");
------------------------------
ZAFIRIS KERAMIDAS
------------------------------
Original Message:
Sent: Thu October 26, 2023 08:25 AM
From: Tracy Green
Subject: Is there an easy way to get an item out of a Name-Value Pair List?
Hello,
I have a UCA that is receiving a Name-Value Pair list. Is there an easy way to retrieve an item with a particular name?
For example, I want the value of the pair where Name = "Account Number" so I can assign it to a variable.
I know I can iterate through the list, but was wondering if there was an easier way.
Thanks!
Tracy
------------------------------
Tracy Green
------------------------------