I have 2 array:
<code>var array1 =
[{"name":"abc", "url":"http:://example1.com"},
{"name":"cde", "url":"http:://example2.com"},
{"name":"fgh", "url":"http:://example3.com"}];
var array2 =
[{"id":"1", "url":"http:://example1.com"},
{"id":"2", "url":"http:://example2.com"}];
</code>
<code>var array1 =
[{"name":"abc", "url":"http:://example1.com"},
{"name":"cde", "url":"http:://example2.com"},
{"name":"fgh", "url":"http:://example3.com"}];
var array2 =
[{"id":"1", "url":"http:://example1.com"},
{"id":"2", "url":"http:://example2.com"}];
</code>
var array1 =
[{"name":"abc", "url":"http:://example1.com"},
{"name":"cde", "url":"http:://example2.com"},
{"name":"fgh", "url":"http:://example3.com"}];
var array2 =
[{"id":"1", "url":"http:://example1.com"},
{"id":"2", "url":"http:://example2.com"}];
I want to filter array1 with url values that are only in array2 but can’t figure out how. I only know how to find with instructions with array2 as a one-dimensional array.
Thank!
I known multi-dimensional array2, I apply the method of reduce array2 to 1-dimensional arrays. But I want to understand more about how to filter directly from 2 arrays 2-dimensional.
<code>let array2b = array2.reduce((acc, cur) => [...acc, cur.url], []);
var filtered = array1.filter(item => array2b.includes(item.url));
</code>
<code>let array2b = array2.reduce((acc, cur) => [...acc, cur.url], []);
var filtered = array1.filter(item => array2b.includes(item.url));
</code>
let array2b = array2.reduce((acc, cur) => [...acc, cur.url], []);
var filtered = array1.filter(item => array2b.includes(item.url));
1