Given two arrays, I am looking to identify the elements in array2 that match elements in array1 based on a specific property.
The arrays are structured as follows:
var array1 = [
{"myId": 1, "text": "a"},
{"myId": 1, "text": "b"},
{"myId": 2, "text": "c"},
{"myId": 3, "text": "d"},
{"myId": 4, "text": "e"},
{"myId": 5, "text": "f"}];
var array2 = [
{"myId": 1, "value": "1x1"},
{"myId": 1, "value": "2x2"},
{"myId": 2, "value": "3x3"},
{"myId": 6, "value": "4x4"},
{"myId": 7, "value": "5x5"}];
I aim to extract the objects from array1 that have matching myId values in array2.
The expected output should be an array like this:
var result = [
{"myId": 1, "text": "a"},
{"myId": 1, "text": "b"},
{"myId": 2, "text": "c"}];
I have experimented with filter and include methods but have not been able to achieve the desired outcome yet.