How to filter data from one array based on another array

Suppose i have 2 array
arr1=["a","b","c","d","e"]
arr2 = [1,3]
Required output arr1 = ["b","d"]

2 thoughts on “How to filter data from one array based on another array”

  1. I assume that you want the value of the first array with the index provided in the second array. You can achieve that with the following approach

    arr2.forEach(value => d.push(arr1[value]))
    
    Reply

Leave a Comment