0

I have a code like this...

function diagnoseprint() {
document.getElementById('goeshere').innerHTML=localStorage['timetable'];
var decode = JSON.parse(localStorage['timetable']);
var step = decode.timetable.UCFF1201ENG.2;
document.getElementById('goeshere').innerHTML=step[1];}

and the localStorage['timetable'] is actually 500KB stuff I'm not gonna post here all of it, I post a bit of it...

{"meta":{"week":"2012-02-13","lastsync":"1329415763","jsontime":1329456671},"timetable":{"TPMF1101MBA":{"1":["MON,13-Feb-12","08:45 - 10:15","L2 - 12","TPM","BSB20133-M-BRM-L","DR. TAN JUAT HONG"],"2":["WED,15-Feb-12","10:35 - 12:05","L2 - 12","TPM","BSB20133-M-BRM-T","DR. TAN JUAT HONG"]},

I wonder why I can't extract that bit, BTW I'm just starting out on JavaScript.

Ates Goral
  • 137,716
  • 26
  • 137
  • 190

1 Answers1

2

Instead of:

var step = decode.timetable.UCFF1201ENG.2;

Use:

var step = decode.timetable.UCFF1201ENG[2];

2 is not a valid identifier, so it cannot be used in the dot notation. Use the bracket notation, which does absolutely the same thing.

Ates Goral
  • 137,716
  • 26
  • 137
  • 190