JavaScript realizes the longest substring of non repeated characters

simple rough direct code

is easy to understand with console, the code is as follows:

    var lengthOfLongestSubstring = function (s) {
      var arr = [];
      var max = 0;
      for (let index = 0; index < s.length; index++) {
        var a = arr.indexOf(s[index]);
        console.log(a, s[index], 222)
        if (a != -1) {
          arr.splice(0, a + 1)
          console.log(111, arr, max)
        }
        arr.push(s.charAt(index))
        console.log(arr, 222)
        max = Math.max(arr.length, max)
      }
      return console.log(max, arr)

    };
    lengthOfLongestSubstring('abcdeasasas')

Read More: