reading a JSON in an array | Sololearn: Learn to code for FREE!
Neuer Kurs! Jeder Programmierer sollte generative KI lernen!
Kostenlose Lektion ausprobieren
+ 2

reading a JSON in an array

["{"name":"John","org":"QWERTY","con1":"08q","con2":"1","comment":"CA"}"] //code to read above window.onload=function(){ var ls=localStorage.getItem("contact"+document.cookie.split("=")[1]);//cookie=(username=abc) var arr=JSON.parse(ls); console.log(arr.org);//result=undefined } How can we read above json as an object.like var a=object_name.name(//output )=John;

30th Jan 2020, 5:26 PM
𝖆𝖙.𝖚𝕷
𝖆𝖙.𝖚𝕷 - avatar
3 Antworten
30th Jan 2020, 5:53 PM
Taste
Taste - avatar
+ 1
like this ? jsonObj[0].name or you can use for loop if there are more than 1 object in the array for(let obj of jsonObj) obj.name;
30th Jan 2020, 5:37 PM
Taste
Taste - avatar
+ 1
#Taste thanks
30th Jan 2020, 5:55 PM
𝖆𝖙.𝖚𝕷
𝖆𝖙.𝖚𝕷 - avatar