Reputation: 2485
Morning,
I have wrote a function to fetch the data from json and return the value back, but its saying SyntaxError: Unexpected token u
Second Function
function fetchData(u, c, k) {
return JSON.parse(localStorage[u + c][k]);
}
Logging
console.log(fetchData(username, centre, "date"));
Error Uncaught
Upvotes: 0
Views: 81
Reputation: 780688
It should be:
function fetchData(u, c, k) {
return JSON.parse(localStorage.getItem(u + c))[k];
}
Upvotes: 3
Reputation: 23208
Try this
function fetchData(u, c, k) {
return JSON.parse(localStorage[u + c])[k];
}
Upvotes: 2