I have an array of objects that I am mapping through. I would like to append it into an unordered-list in my html file. This what I am currently trying to do. I am getting this error " Uncaught TypeError: Cannot read property 'appendChild' of null".
var newWorkArray= works.map(function(work){
return {
name : work.name,
title : work.title,
pic : work.pic,
link : work.link,
github : work.github
};
});
console.log("newArray", newWorkArray);
const workLiTag= document.createElement("li")
const workItem= document.createTextNode(newWorkArray)
workLiTag.appendChild(workItem)
document.getElementById("#work-items").appendChild(workItem)
I dont think its needed but I'll add the array of objects
var works = [
{
name:"Lorem Ipsum",
title: "Lorem Ipsum",
pic: "Lorem Ipsum",
link: "Lorem Ipsum",
github:"Lorem Ipsum"
},
{
name:"Ruby on Rails | Vue",
title: "Project Manager",
pic: "Lorem Ipsum",
link:"Lorem Ipsum",
github:"Lorem Ipsum"
},
getElementById("#work-items")should not contain#. There is no element with an ID equal to"#work-items"sogetElementByIdreturnsnulldocument.createTextNode(newWorkArray)will result in this text node:"[[objectObject],[objectObject],...]", useJSON.stringifyor construct DOM elements for each property.