I want to put in two columns: "id | Name", but it does not work.

const obj = { data: [{ id: "1236", name: "Friend name" }, { id: "1235", name: "Friend name" }] } obj.data.map(x => document.write(x.name)) obj.data.map(y => document.write(y.id)) 

    3 answers 3

    Well, you first display all the name, then all the id. Display the name immediately | id

     const obj = { data: [ { id: "1236", name: "Friend name" }, { id: "1235", name: "Friend name"} ] } obj.data.map(x => { document.write(x.name + ' | ' + x.id + '<br>') }) 

      Because you first will display all the names then all the id.
      Therefore, we immediately remove them as a couple.

       const obj = { data: [{ id: "1236", name: "Friend name" }, { id: "1235", name: "Friend name" }] } obj.data.map(x => document.write(x.name + " - " + x.id + "<br>") ); 

      • I do not know how best. Just then I want other names in the name and sort them alphabetically. Here it is. - Owl_Livi

      You can do this:

       const obj = { data: [{ id: "1236", name: "Friend name" }, { id: "1235", name: "Friend name" }] } obj.data.map(function(x) { var element = document.createElement("p"); element.innerHTML = `${x.id} | ${x.name}`; document.body.appendChild(element); })