Getting length of array returned by a regex?
Hello I am practicing JavaScript and I got in a little problem I can’t figure out: I’m trying to get an array containing all occurrences from a regex in JavaScript and I’m doing something like this: var str = “This IS a trY”; var pattern = /[A-Z]/g; var matches = str.match(pattern); And till now it all works because if I do console.log(matches) it will print out something like this ( T, I, S, Y ) Just like it usually do with arrays, so I am assuming that in this case the match method is returning an array with all occurrences from the regex. The problem is that I would like to get the length of this array, but if I do matches.length as we usually do for an array I will get an error... so should I assume that the method is not actually returning an array? Is there a better way to do what I’m trying to do?