After calling the .string method on a string and assigning it to another variable, I am getting back an array containing the values for match, index, and input. However, when I attempt to access the second element in the array, it shows up as undefined. Can someone please explain why this is happening? Here's my code snippet:
var str = "hello world";
var matchArray = str.match("ell");
=>matchArray = ["ell",index:1,input:"hello world"]
var index = matchArray[1];
console.log(index);
=>undefined
Any help would be greatly appreciated. Thank you!