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)) 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)) 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>") ); 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); }) Source: https://ru.stackoverflow.com/questions/784484/
All Articles