Ваш код выдает ошибку «Uncaught TypeError: Cannot read property 'children' of null», см. Инструменты разработчика> Консоль для получения дополнительных сведений.
Вы должны обрабатывать свой код для любых пустых значений, таких как null, неопределенный. Просто измените свой код на этот:
let main_dashboard_items = document.getElementById('main_dashboard').children;
let main_dashboard_items_array = [];
/*let main_dashboard_items = [];
for (let i = 0; i < main_dashboard_items_html.length; i++) {
// At this point we could also push the elements to an array
main_dashboard_items.push(main_dashboard_items_html[i]);
}*/
for(let i=0; i<main_dashboard_items.length; i++){
// console.log(main_dashboard_items[i].children[0].currentSrc); --> returned undefined
// console.log(main_dashboard_items[i].href); --> returned undefined
//console.log(main_dashboard_items[i].getAttribute("href")) --> returned "null"
let item_arr = {'url': main_dashboard_items[i].getAttribute("href"),
'text': main_dashboard_items[i].innerText,
'image': main_dashboard_items[i].children[0] ? (main_dashboard_items[i].children[0].children && main_dashboard_items[i].children[0].children.length > 0 ? main_dashboard_items[i].children[0].children[0].currentSrc : "") : ""
};
main_dashboard_items_array.push(item_arr);
console.log(main_dashboard_items_array);
}
EDIT
Теперь попробуйте следующее:
let main_dashboard_items = document.getElementById('main_dashboard').children;
let main_dashboard_items_array = [];
/*let main_dashboard_items = [];
for (let i = 0; i < main_dashboard_items_html.length; i++) {
// At this point we could also push the elements to an array
main_dashboard_items.push(main_dashboard_items_html[i]);
}*/
for(let i=0; i<main_dashboard_items.length; i++){
// console.log(main_dashboard_items[i].children[0].currentSrc); --> returned undefined
// console.log(main_dashboard_items[i].href); --> returned undefined
//console.log(main_dashboard_items[i].getAttribute("href")) --> returned "null"
let item_arr = {'url': main_dashboard_items[i].children[0].getAttribute("href"),
'text': main_dashboard_items[i].children[0].children[1].innerText,
'image': main_dashboard_items[i].children[0].children[0].children[0].src,
'anotherImage' : main_dashboard_items[i].children[0].children[0].children[1].src
};
main_dashboard_items_array.push(item_arr);
console.log(main_dashboard_items_array);
}