I have encountered an issue while attempting to solve this problem. Despite reviewing various solutions provided here, I am consistently facing an error related to the pop() method.
The situation involves handling a multidimensional array in JavaScript where I need to remove sensitive information (e.g., Social Security Numbers) and return the modified array.
My initial strategy involved utilizing a foreach loop and the pop() function to eliminate the SSN element from each child array.
However, upon testing the code using Node in the command line, I kept getting an error message stating that element.pop() is not recognized as a function. I attempted alternatives like pop(), slice(), and filter(), but none of them worked successfully.
Upon running $> node filename.js,
H:\Apache2\htdocs\test\filename.js:50 noppi[i] = element.pop(); ^
TypeError: element.pop is not a function
let recs = [
{
ID: 1,
NAME: 'John',
EMAIL: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="c8a2a7a0a688adb0a9a5b8a4ade6aba7a5">[email protected]</a>',
SSN: '123'
}, {
ID: 2,
NAME: 'Sally',
EMAIL: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="d9aab8b5b5a099bca1b8b4a9b5bcf7bab6b4">[email protected]</a>',
SSN: '456'
}, {
ID: 3,
NAME: 'Angie',
EMAIL: '<a href="/cdn-cgi/l/email-protection" class="__cf_email__" data-cfemail="2d4c434a44486d48554c405d4148034e4240">[email protected]</a>',
SSN: '789'
}
];
let i = 0;
let noppi = [];
recs.forEach(element => {
noppi[i] = element.pop();
i++;
});
console.log(noppi);