I am currently looping through an array and inspecting each value. Depending on certain conditions, I am moving the value to another array. However, in this case, I am focused on counting the number of periods in each item of the array.
Below is the snippet of code I am working with:
for(i = 0; i < (sortarray.length) -1; i++)
{
var count = (sortarray[i].match(/./g)||[]).length;
console.log(count + ' periods found in name' + sortarray[i]);
if (count > 1)
{
alert('Error: One or more filenames contain periods.');
return;
}
else ...
File names typically have one period, while folder names do not have any. If a value contains more than 1 period, an alert message should be displayed. Despite seeming straightforward, my variable is unexpectedly returning 100 instead of 1, resulting in the alert box always appearing.
Is there a more effective method to count the dots in each value of the array?