Dan
Dan

Reputation: 1295

breaking down a string into separate variables

I need to be able to break down a string into separate variables based on a :

Here are two possibilities of two separate strings

localAction:connectPage
localAction:product:<Id>

I want to break this down into

first variable = name

second variable (if set) = id.

Upvotes: 0

Views: 102

Answers (1)

Alex Wayne
Alex Wayne

Reputation: 187034

To expand on esqew's comment...

var string = "localAction:connectPage";
var pair = string.split(":"); // the magic
var name = pair[0];
var id = pair[1];

console.log(name); // "localAction"
console.log(id);   // "connectPage"

Upvotes: 1

Related Questions