• As @fanoush says you can use indexOf - there's actually an example of this in the planetarium app: https://github.com/espruino/BangleApps/b­lob/master/apps/planetarium/planetarium.­app.js#L107

      f=storage.read("...");
      var line,linestart = 0;
      lineend = f.indexOf("\n");
      while (lineend>=0) {
        line = f.substring(linestart,lineend);
        .... = line.split(',');
        linestart = lineend+1;
        lineend = f.indexOf("\n",linestart);
      }
    

    Just a bit of background: Storage.read returns a string that's basically just a pointer to external flash memory - so it can be huge. You can use it like any other string, but if you split it you're then creating potentially thousands of new strings in RAM which will use up all the available memory.

    I guess there's no JavaScript function that is the equivalent of .split(..).forEach(..) but I guess it's something we could add.

About

Avatar for Gordon @Gordon started