const categories = [{_id:'5d636c50349128976d09806a',catName:'Banking',catClass:'banking',userId:''},
{_id:'5d636c50349128976d09806b',catName: 'Torrents', catClass: 'torrents', userId:''},
{_id:'5d636c50349128976d09806c',catName: 'AudioBooks', catClass: 'audiobooks', userId:''}];
const pages = [
{id: 0, name: 'N-0', link: '', ctgrId: '5d636c50349128976d09806a',userId: '',screen:''},
{id: 1, name: 'N-1', link: '', ctgrId: '5d636c50349128976d09806a',userId: '',screen:''},
{id: 2, name: 'N-2', link: '', ctgrId: '5d636c50349128976d09806a',userId: '',screen:''},
{id: 3, name: 'N-3', link: '', ctgrId: '5d636c50349128976d09806c',userId: '',screen:''}]
function getPagesArr(pages, categories) {
var map = categories.reduce((m, {_id, catClass}) => ({[_id] : catClass, ...m}), {});
return pages.map( p => {
var v = {...p, ctgrId : map[p.ctgrId] || p.ctgrId};
return v;
});
}
const newArray = getPagesArr(pages, categories);
console.log(newArray)