how in json to output string j in html

window.a = window.a || { b: {}, c: {}, d: { e: { } }, f: {}, g: {} ,h: { ,k: [] ,l: [] ,j: ['{"1": 2,"3": "4" }}' ] } }; 
  • You have one bracket in j extra. - Andrew Evt
  • and J in this context is not 'string' - Dmitriy Gvozd
  • but how do you say to output 2 element from J - mr.robot

1 answer 1

if you remove all unnecessary, and you want to display the text {"1": 2,"3": "4"}

 window.a = window.a || { b: {}, c: {}, d: { e: {} }, f: {}, g: {}, h: { k: [], l: [], j: ['{"1": 2,"3": "4"}'] } }; alert(ahj); 

https://jsfiddle.net/qdmez78w/ - demo

For more detailed familiarization with the work with objects:

  1. https://learn.javascript.ru/object
  2. https://developer.mozilla.org/ru/docs/Web/JavaScript/Guide/Working_with_Objects
  3. https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/JSON
  • but how do you say to output 2 element from J - mr.robot
  • one
    @ mr.robot, there is no second element there, the line is. - Visman
  • This is actually an array. To display it, you need to convert the value to an object. JSON.parse(ahj[0])["3"] will display 4 jsfiddle.net/qdmez78w/1 - Andrew Evt