Brarord
Brarord

Reputation: 651

How to get only part of text from string value?

Guys if i have string like that:

var tmp1 = "🔑 TakeMe 🔑";

Is this possible (in some easy way) to get text from that variable, but only "TakeMe"? "TakeMe" is beetwen spaces.

var tmp2 = tmp1;  

tmp2 == "TakeMe" not "🔑 TakeMe 🔑"

Well guys you know what i mean. Can someone help me with this? My JS skills are really bad ^^

Upvotes: 0

Views: 287

Answers (2)

Aziz.G
Aziz.G

Reputation: 3721

you better use regex

var tmp1 = "🔑 TakeMe 🔑";

var [text] = tmp1.match(/[a-zA-Z]+/g);
console.log(text);

Upvotes: 1

Nikhil Goyal
Nikhil Goyal

Reputation: 1973

Try this code.

var tmp1 = " TakeMe ";

var tmp2 = tmp1.trim();
console.log(tmp2);

Upvotes: 0

Related Questions