, чтобы помочь мне разобраться в том, что происходит, я использую codepen.io
Я использовал следующий код и хотел получить индекс второго экземпляра regex. < /p>
Код: Выделить всё
function findZip(str) {
return [...str.matchAll(/zip/g)];
}
console.log(findZip("Zip is a file format used for data compression and archiving. A zip file contains one or more files that have been compressed, to reduce file size, or stored as is. The zip file format permits a number of compression algorithms."))
< /code>
Codepen и Jsfiddle только возвращают значение режима в массиве [[Zip], [Zip]], но запуск того же кода в консоли браузера возвращает полный массив с включенным индексом. < /p>
(2) [Array(1), Array(1)]
0
:
['zip', index: 64, input: 'Zip is a file format used for data compression and…ormat permits a number of compression algorithms.', groups: undefined]
1
:
['zip', index: 169, input: 'Zip is a file format used for data compression and…ormat permits a number of compression algorithms.', groups: undefined]
length
:
2
[[Prototype]]
:
Array(0)
Спасибо за ваше время.
Подробнее здесь: https://stackoverflow.com/questions/796 ... lts-and-is
Мобильная версия