+ 1

can any one help me with this code ...i want to show entered hestory data

https://code.sololearn.com/W5A5tXDC84ox/?ref=app

22nd Oct 2017, 9:01 PM
khaled Abu Alheja
khaled Abu Alheja - avatar
5 Answers
+ 4
If you know the index of object to be accessed: userData[index]["age"] I guess that you don't, so you need to iterate over userData array to find matching object (where userData[index]["name"]=="Raas" in your example) and use that index to access the object property you want... There are many ways to achieve this: with for/while classic loop, as well as with advanced Array object methods (some require latest javascript implementations, but are mostly supported today)... var found = false; var index = userData.length; while (index--) { if (userData[index]["name"]=="Raad") { found = true; break; } } if (found) { /* do what you want with userData[index] object */ alert("Raad age is "+userData[index]["age"]); // or: userData[index].age } else { /* do something (or not) in case of not found */ alert("Error: name not found!"); }
23rd Oct 2017, 9:58 PM
visph
visph - avatar
+ 4
Cookies and web storage (both localStorage and sessionStorage) doesn't work in mobile application context: it's a feature available only in web browsers context ^^
23rd Oct 2017, 2:02 PM
visph
visph - avatar
+ 3
Your code is messy, and your goal is unclear ^^ Anyway: > document.getElementById(index).style.color=user[index]["preferdcolor"]; cannot work, as you don't provide any id to any element, and you only pass a number as argument; > localStorage("i",++index); cannot work, and I don't know what you're expected with this line: localStorage is not a function (you probably miss the dot and the method name ^^); > localstorage.setItem("form",document.getElementsByTagName("form")[0].outerHTML); I cannot understand what's your goal with this line anymore: this will store the outerHTML previously changed with <ul> list dynamically builded?... into the localStorage key 'form' wich you doesn't use elsewhere???
23rd Oct 2017, 5:48 PM
visph
visph - avatar
0
i know but there is abroblem in my code ...
23rd Oct 2017, 5:34 PM
khaled Abu Alheja
khaled Abu Alheja - avatar
0
i have some problems.. 1. iwant to store an array of object (json). 2. i failed in getting length to an stored array becouse of that i store an index that get begger each time. my problem is how can i steItem/getltem of this for example: userData=[{"name":"Khaled","age":30,"birthday":"02/02/12"} {"name":"Gel","age":23,"birthday":"22/12/12"} {"name":"Raad","age":40,"birthday":"18/07/78"}] how can i get "Raad" age for example..?
23rd Oct 2017, 9:10 PM
khaled Abu Alheja
khaled Abu Alheja - avatar