Answer the question
In order to leave comments, you need to log in
How to collect json?
There are elements on the page, an indefinite number of views
<div class=cartitem">item 1</div>
<div class=cartitem">item 2</div>
...
"items": [
{
"name": "item 1"
},
{
"name": "item 2"
}
]
Answer the question
In order to leave comments, you need to log in
If you are interested in an option with lower memory and CPU costs than Alexander
const items = Array.from(
document.getElementsByClassName('cartitem'),
({textContent}) => ({name: textContent})
);
const itemsJSON = JSON.stringify(items);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question