substring vs match

Edit on GitHub

Setup

var haystack = '[[apple]][[banana]][[cherry]]';

Tests

  • substring

    haystack.substring(0, 2) === '[[';
  • match

    haystack.match(/^\[\[/);