Activity Forums Salesforce® Discussions How to remove an element placed at an index from an array in Salesforce?

  • Prachi

    Member
    November 20, 2019 at 6:44 am

    Hi,

    Find the index of the array element you want to remove, and then remove that index with splice.

    The splice() method changes the contents of an array by removing existing elements and/or adding new elements.

    var array = [2, 5, 9];
    console.log(array)
    var index = array.indexOf(5);
    if (index > -1) {
    array.splice(index, 1);
    }
    // array = [2, 9]
    console.log(array);

    Thanks.

Log In to reply.

Popular Salesforce Blogs

Popular Salesforce Videos