0

I have the following code:

for(i = 0; i < textArray.length; i++)
        {
            var reg = /\bSTEAM_[01]:[01]:[0-9]{1,10}\b/;
            var correctID = textArray[i].match(reg);

            if(correctID !== null)
            {
                var z = correctID.split(':');

                var correctID64 = '765611' + 97960265728 + z[3];

                steamIDs.push(correctID64);
                alert(correctID64);
            }
        };

However, I get an uncaught type error: "Uncaught TypeError: Object [object Array] has no method 'split'" when I try to split correctID. To my understanding, correctID should be a string, and when I try to dump an index of correctID, it fails. However, when I dump the data type it comes back with [Object Array].

Why is correctID getting treated like an array? I'm assigning it a new value each time the loop runs, not adding values to an array.

2 Answers 2

1

match() returns an array containing all matches. It does not return a string.

Docs

Sign up to request clarification or add additional context in comments.

Comments

0

The .match() function returns an array. Here is reference.

You may try:

var correctID = textArray[i].match(reg).toString(); 

or if you need just first occurence:

var correctID = textArray[i].match(reg)[0]; 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.