I have 2 array:
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.
Thank VLAZ about Array Definition. (I thought my example would be a 2-dimensional array).
I known multi-object item array2, I apply the method of reduce array2 to new arrays. But I want to understand more about how to filter directly from 2 arrays with multi object items.
let array2b = array2.reduce((acc, cur) => [...acc, cur.url], []);
var filtered = array1.filter(item => array2b.includes(item.url));
EDIT: I spent a day searching but didn't expect it to be here: Filter array of objects with another array of objects . sorry all
[[1], [2, 3], [4, 5, 6]]is a 2D array - an array of arrays.