In the code snippet below, I am trying to work with file names:
var completename = file.name;
var regex = '/-\w+_/';
var filenameTest_components = completename.match(/-\w+_/);
console.log(completename);
console.log(typeof filenameTest_components, filenameTest_components)
My goal is to utilize the first two elements of the array `filenameTest_components`. However, I encounter an error when attempting to print the first element:
console.log(filenameTest_components[1])
TypeError: Cannot read property '1' of null
This error has left me puzzled as to whether the `match` method should return an `array` or an `object`?
The current output from printing just the input string and match output appears as follows:
task-routelearning_events.json
object [ '-routelearning_',
index: 4,
input: 'task-routelearning_events.json' ]
Edit:
To provide a broader context, here is the link to the related GitHub repository: