How to remove a data from datatables pushed an array (maybe with pop) (javascript)

let array = [];
//you can try with a email that doens't exist into the array
let email = '[email protected]'
let recipientData = {
                        name: 'prueba1',
                        email: '[email protected]',
                    recipientData = {
                        name: 'prueba2',
                        email: '[email protected]',
//im creating two new elemnts into the array
//here we going to find the key of the element comparing the email
const index = array.findIndex(el => === email);
    if (index === -1) {
    //if don't existe you can create a new one
    console.log('dont exist')
    // and if exist we removed, array.splice(), index, and we specific than removed exactly one
    const removed = array.splice(index, 1)
    //and return the element removed
    // and console.log array to verify

Hi, I leave you an example and the specifications of the code I leave it with comments in the code.

CLICK HERE to find out more related problems solutions.

Leave a Comment

Your email address will not be published.

Scroll to Top