msheshtawy
msheshtawy

Reputation: 415

How to split strings

I have tried Split("?") and Split('?'). Both give the same error (link.split is not a function), so i assume that there is a way to be able to split but not using this Split? Maybe jQuery?

Edit: Got it, it should be href.split. So as jordan said, it was not a string. So i used x.href.split("?") and it worked like a charm.

Upvotes: 0

Views: 199

Answers (2)

Samuel Neff
Samuel Neff

Reputation: 74949

If the object is not already a string, convert it first.

myObject.toString().split("?");

Upvotes: 0

Jordan Running
Jordan Running

Reputation: 106077

Jetpack just uses JavaScript so this should work:

var str = "My.string";
str.split("."); // => [ "My", "string" ]

If it tells you "split is not a function" then it probably means your variable doesn't hold a string like you think it does.

Upvotes: 1

Related Questions