I'm trying to write a function that uses a regex to filter an array of names and returns a new array that contains only those individuals with a given last name. The issue is that it will only return one instance. I feel it's likely due to the regEx - can anyone help?
function getSmith(arr) {
const regex = /Smith$\b/g;
return arr.filter(name => regex.test(name));
}
console.log(
getSmith(['John Smith', 'Chris Smith'])
)