'Changing className to value from an array

I have a piece of code:

let allItems = document.querySelectorAll(".cars-database-collection-item");

let allModels = $('.cars-tab-vehicle--model-span').map(function() {
  return this.textContent;
}).get();

which gives me:

allModels - ['A7 55 TFSIe PHEV', 'A9 e-tron', 'e-tron', 'e-tron GT', 'e-tron Sportback', 'Q4 e-tron quattro', 'Q4 Sportback e-tron', 'Q5 55 TFSIe PHEV', '330e', '530e']

allItems = NodeList(10) [div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item, div.cars-database-collection-item.w-dyn-item]

I want to replace all classes:

cars-database-collection-item.w-dyn-item

with (respectively) a names from an array.

What I tried:

window.addEventListener("load", () => {
allItems.forEach((n) => 
    function changeClass(value){
    class = allModels;
    allItems.className = class[value];
}
)   
})

Any kind of help appreciate.



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source