I have a working code snippet as shown below:
var sidebar1 = document.querySelector("[data-language-key='sidebar-1']").innerHTML;
However, I am looking to enhance the scalability by creating an array sidebar
and using a for
loop to store all the text values of sidebar-X
. I have attempted to write something for this purpose but struggling with the syntax.
var sidebar = [];
for (var i = 1; i <= 6; i++) {
sidebar.push(document.querySelector(`[data-language-key=`
'sidebar-' + i ``).innerHTML);
}