Keep Matching Values Along With Other Values in Array

Discussão em 'Angular' iniciado por user8512043, Novembro 12, 2024.

  1. user8512043

    user8512043 Guest

    I've a requirement, not sure if it's doable. Something as follows:

    Array 1:

    var arr1 = ['prop1: 123', 'prop2: 234', 'prop3: 567', 'prop4: 8910'];


    Array 2:

    var arr2 = ['prop1: 123', 'prop2: 234'];


    On the fly, I've to get the following if arr2 matches arr1, then it should return the a new array or arr1 as follows:

    var arr1 = ['prop1: 123', 'prop2: 234', 'prop3: 567', 'prop4: 8910'];


    If the arrays are like this:

    Array 1:

    var arr1 = ['prop1: 123', 'prop2: 234', 'prop3: 567', 'prop4: 8910'];


    Array 2:

    var arr2 = ['prop2: 234'];


    Then I should have the following:

    var arr1 = ['prop2: 234', 'prop3: 567', 'prop4: 8910']; //As 'prop1: 123' isn't in arr2


    This would be done with a select event of a drop down box. Is there any way to match in such a way? The same could happen to the following as well:

    Array 1:

    var arr1 = ['prop1: 123', 'prop2: 234', 'prop3: 567', 'prop4: 8910'];


    Array 2:

    var arr2 = ['prop3: 567'];


    Then I should have the following:

    var arr1 = ['prop1: 123', 'prop2: 234', 'prop3: 567']; //As 'prop4: 8910' isn't in arr2

    Continue reading...

Compartilhe esta Página