user2342350
user2342350

Reputation: 101

Extract string with javascript

need to extract the string from this ["IBM"], have to get IBM, I have tried like this

(/['"]/g,'') way.
var extractor=(/['"]/g,'');
       var newArr = extractor.exec(NAME);

               alert(newArr);

Upvotes: 2

Views: 77

Answers (3)

Anand Shah
Anand Shah

Reputation: 180

This should get you an array of all the matches

var matches = mystring.match(/\[\"(.*?)\"\]/g);

Upvotes: 1

user
user

Reputation: 545

Try this :

//variable contains ["IBM"]
variable = variable.substr(2,3);

This will work only if the text between the [""] length is 3

Upvotes: 0

SLaks
SLaks

Reputation: 887285

You should parse that as JSON:

var array = JSON.parse(input);
alert(array[0]);

Upvotes: 4

Related Questions