-2

so i have this:

    "list": [
        {
            "name": "first",
            "author": "1",
            "id": 67180129,
            "vid": "https://www.youtube.com/watch?v=kwpM60h46PY&ab_channel=WhiteChocolateTwo"
        },

        {
            "name": "second",
            "author": "2",
            "id": 67089023,
            "vid": "https://www.youtube.com/watch?v=invRaEdZNwE"
        }
    ]
};

and i want to make that on an index.html file i can get access to "name": "first" on <p>, how do i get that?

JvstAlf
  • 83
  • 1
  • 9
  • 1
    Do you mean you would like to change the content of a paragraph to include the content `"name": "first"`? Please may you explain? At the moment it is unclear what issue you're facing – evolutionxbox Mar 09 '21 at 16:20
  • @evolutionxbox yeah i want to have like

    with an id and then i want here to have info from that file so like i need to have access to list then "name": "first"

    – JvstAlf Mar 09 '21 at 16:24
  • Good, you know what you would like to do. What part are you struggling with? – evolutionxbox Mar 09 '21 at 16:26
  • @evolutionxbox i dont know how to get access to that element so i can write its content on

    – JvstAlf Mar 09 '21 at 16:27
  • Iterate over data in your js file with js code and create HTML elements with innerText or innerHtml DOCS HERE: https://developer.mozilla.org/ru/docs/Web/API/Document/createElement But better way is to use "JS Template Engine" – Maxim Colesnic Mar 09 '21 at 16:27
  • @MaximColesnic i didnt ask for that – JvstAlf Mar 09 '21 at 16:30
  • the element needs to be selected first https://stackoverflow.com/a/10693852/989920 – evolutionxbox Mar 09 '21 at 16:32
  • @evolutionxbox that didnt help me i just need to know how to access it like ```shitty.list.name[0]``` or something thats the point i dont know how to write that i need to get the value that is contained on "name" inside the first two brackets – JvstAlf Mar 09 '21 at 16:37
  • list[0]['name'] or list[0].name – Maxim Colesnic Mar 09 '21 at 16:41
  • @MaximColesnic thanks – JvstAlf Mar 09 '21 at 16:43
  • arrayOrObjectInJs[indexOrProperty] = value :) – Maxim Colesnic Mar 09 '21 at 16:44
  • @JvstAlf right that's cool. May you update the question to include an [mcve] of what you're trying? HTML/JS included? Otherwise we're kinda guessing at what you're struggling with – evolutionxbox Mar 09 '21 at 16:44

1 Answers1

0

If you are not using a framework, you have to do it in your js-code. Just select the <p> element and set its text to your data.

If you only want to use HTML you have to set that value by hand.

andi2.2
  • 86
  • 1
  • 11