var selectedField = component.get("v.selectedField");
var resultArray = selectedField.split(',');

when I use split method display this error,who could tell me why? Error: Uncaught Action failed: [selectedField.split is not a function]

  • 1
    Without knowing what "selectedField" is, we have no way to tell you precisely, but clearly you're not using it on a String object.
    – sfdcfox
    Oct 27, 2018 at 16:10
  • "selectedField" is:<aura:attribute name="selectField" access="public" type="String" />
    – One
    Oct 27, 2018 at 16:23
  • when I write this to test whether split method could use, it works. var str = '55;99'; str = str.replace(";","") console.log('str'+str);
    – One
    Oct 27, 2018 at 16:28

1 Answer 1


Thanks your help. Because my selectField is used in lightning:select value="{!v.selectField}". I add a toString method convert to String and now it works.

var resultArray = selectedField.toString().split(',');
  • 1
    Sometimes the values you get from an aura:attribute are weird wrapper objects built into Lightning instead of native JS objects. Or you might get something like an array containing one string instead of a string. So yeah you occasionally have to coerce it to the right type to manipulate it.
    – Charles T
    Oct 27, 2018 at 16:45
  • 1
    Now that you specify it's from lightning:select that makes sense. It's exactly as I was saying - it returns an array instead of one String, because the same component is also capable of multi-select.
    – Charles T
    Oct 27, 2018 at 16:46

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .