split()

Posted on
  • Sorry Gordon,

    Found another bug.

    'HELLO'.slpit('');

    returns:
    =[
    "HELLO"
    ]

    Should return:

    ["H", "E", "L", "L", "O"]

    Sacha

  • For me it's ok because you do not have the " separator in the 'HELLO' string so you get the same string as the result.

  • No, that's an empty string. A " separator would be '"' (a double quote enclosed in single quotes)

    Correct behavior is to split a word up into letters like Sacha said - try it in any js console.

    'HELLO'.split('');
    ["H", "E", "L", "L", "O"]
    
  • https://developer.mozilla.org/en-US/docs­/Web/JavaScript/Reference/Global_Objects­/String/split

    Syntax

    str.split([separator][, limit])

    Parameters

    separator

    Specifies the character(s) to use for separating the string. The separator is treated as a string or a regular expression. **If separator is omitted, the array returned contains one element consisting of the entire string**. If separator is an empty string, str is converted to an array of characters.
    
  • So you are right.

  • Also

    """
    "HELLO".split();
    =["", "H", "E", "L", "L", "O"]
    //["HELLO"] expected
    '''"

  • Thanks - I'll try and get a fix for this in the next version.

  • Post a reply
    • Bold
    • Italics
    • Link
    • Image
    • List
    • Quote
    • code
    • Preview
About

split()

Posted by Avatar for Sacha @Sacha

Actions