Get data from div in log?

How to get all href value class"list-item__link" and the contents of class"list-item__date" log
You should get something like this
http://element.ru/user/1 - 01.01.2018
http://element.ru/user/2 - 02.10.2017
http://element.ru/user/3 - 11.11.2017

<div class="list">
<li class="list-item ">

</li>
<li class="list-item ">

</li>
<li class="list-item ">

</li>
</div>
June 8th 19 at 16:31
2 answers
June 8th 19 at 16:33
Not tested, but should work:
var links = document.querySelectorAll('.list-item__link'),
 linksArray = Array.prototype.slice.call(links),
 logArray = [];
linksArray.forEach(function(link){
 logArray.push( link.getAttribute('href') + ' - ' + link.querySelector('.list-item__date').innerHTML );
});
var log = logArray.join('\n');
Not working here, this error comes out
Uncaught TypeError: Cannot read property 'innerHTML' of null
 at <anonymous>:5:92
 at Array.forEach (<anonymous>)
 at <anonymous>:4:12</anonymous></anonymous></anonymous>
- nikita.Stracke commented on June 8th 19 at 16:36
June 8th 19 at 16:35
Not working here, this error comes out
Uncaught TypeError: Cannot read property 'innerHTML' of null
 at <anonymous>:5:92
 at Array.forEach (<anonymous>)
 at <anonymous>:4:12</anonymous></anonymous></anonymous>

Find more questions by tags JavaScript