Is it possible to sort through an array based off a format?
I was looking through Array methods and didn't find one.
I have an array of all strings which may or may not contain phone numbers.
The format of the phone numbers are either (877) 843-2900 or 877-843-2900.
I'm trying to get the index of each string in the array which contains a phone number.
For example:
// Example input:
[
'Call today! Reach us at 314-867-5309 any day of the week.',
'Over 3,148,675,309 people trust ACME for all their road runner needs!',
'(877) 843-2900',
// ...
];
// Example output:
[0, 2, /* ... */];
This is my attempt:
var regex1 = RegExp('/^[\+]?[(]?[0-9]{3}[)]?[-\s\.]?[0-9]{3}[-\s\.]?[0-9]{4,6}$/im','g');
var str1 = 'table football, foosball, (123) 456-7890, 123-456-7890';
var array1;
while ((array1 = regex1.exec(str1)) !== null) {
console.log(`Found ${array1[0]}. Next starts at ${regex1.lastIndex}.`);
}