I am new to JavaScript language.
I have a simple SAC Story that only has one page. This page contains some widgets, with widget Ids, such as: Chart_01, Chart_02..., Chart_04, and Table_01, ... , Table_03
.
I want to write a JavaScript code that would collect the widget ids and store them into a vector or array.
I tried with the code that ChatGPT suggested:
// Create an empty array to hold the widget IDs
var widgetIds = ArrayUtils.create(Type.string);
// Select all widgets by their class and loop through them
document.querySelectorAll('.widget-class').forEach(widget => {
// Add the widget's ID to the array
widgetIds.push(widget.id);
});
// Log the result to see the collected IDs
console.log(widgetIds);
I find this code conceptualy logical, however SAC does not recognise the code snippet bellow the comment // Select all widgets by their class and loop through them
Is there a way to loop over widgets on the page and get their ids and store them into an array?
Thanks