Here is my array along with a loop that retrieves the keys (https://jsfiddle.net/ytm04L53/)
var i;
var feeds = ["test_user_201508_20150826080829.txt:12345","test_user_list20150826:666","test_list_Summary20150826.txt:321"];
for (i = 0; i < feeds.length; i++) {
var feed = feeds[i];
alert(feed.match(/\d+$/));
}
https://i.sstatic.net/F4kB9.jpg
The length of the array may vary, and I want to either use these keys as variables and assign their corresponding values after the :
colon, or create new variables and assign the values from these keys to them.
How can I accomplish this in order to perform comparisons such as:
if (test_user > 5000) {dosomething}
update Thank you for the responses. How can I also create a set of variables and assign the array values to them? For example, like the following:
valCount(feeds.split(","));
function valCount(t) {
if(t[0].match(/test_user_.*/))
var testUser = t[0].match(/\d+$/);
}
Sometimes there may be only one key in the array, other times two or three, so t[0]
will not always be test_user_
I need to pass the array to a function and check for matches. If a key starts with test_user_
, then retrieve the value and assign it to a specific variable.
Thanks everyone for your assistance!