I am attempting to produce an array containing all the Groups on a page. The groups have IDs such as #gTag1, #gTag2 etc, and I am using the following code:
let pageChildren = $w("Page").children;
console.log(pageChildren);
function checkGroup(grp) {
let grpMatch = /gTag/;
return grpMatch.test(grp);
}
let tagIds = pageChildren.filter(checkGroup);
console.log(tagIds);
This returns an empty array, yet if I copy and paste the output of “console.log(pageChildren)” into the Velo code as follows:
let pageChildren = [
"$w('#text1')",
"$w('#line1')",
"$w('#bHelp')",
"$w('#bReset')",
"$w('#dQuantity')",
"$w('#dFont')",
"$w('#dAlignment')",
"$w('#gTag1')",
"$w('#gTag2')",
"$w('#gTag3')",
"$w('#gTag4')",
"$w('#bBuy')",
"$w('#bBacker')",
"$w('#iSize')"
];
function checkGroup(grp) {
let grpMatch = /gTag/;
return grpMatch.test(grp);
}
let tagIds = pageChildren.filter(checkGroup);
console.log(tagIds);
The filter works. Why does it not work in the first instance?