see the NodeJs, here below:
$ node
Welcome to Node.js v12.3.1.
> regexp = /cerca (?<word>.+) su (?<dictionary>wikipedia|treccani|garzanti|google)/i
> string = 'cerca chatbots su wikipedia'
> matchData = string.match(regexp)
[
'cerca chatbots su wikipedia',
'chatbots',
'wikipedia',
index: 0,
input: 'cerca chatbots su wikipedia',
groups: [Object: null prototype] {
word: 'chatbots',
dictionary: 'wikipedia'
}
]
> matchData.groups.word
'chatbots'
> matchData.groups.dictionary
'wikipedia'
The regexp match appear OK to me, and named groups are captured perfectly, but what does it mean the [Object: null prototype] statement in console.log node REPL?
thanks
The [Object: null prototype] means that the __proto__ atribute of the object is equals to undefined. The _proto_ atribute is used on javascript heritance, so it is used on log to auxiliate the identification of classes.
It occurs due to the fact that groups have as keys only the found ones (missing the __proto__). And in that way, you can iterate over keys with for(let key in matchData.groups){...} with 100% of accuracy that key wont assume the "__proto__" value. This design may be unnescessary, but it works.
You can create a common object using Object(matchData.groups) or {...matchData.groups}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With