Iterar dos arreglos match indexes

Para paginación

by borisjavier

JavaScript

const moviesNamesAndGenres = [
   {id: 0, name: "Action"},
   {id: 1, name: "Adventure"},
   {id: 2, name: "Animation"},
   {id: 3, name: "Drama"},
   {id: 4, name: "Terror"},
   {id: 5, name: "Fun"},
   {id: 6, name: "Dance"},
   {id: 7, name: "Entertainment"},
   {id: 8, name: "Realities"},
   {id: 9, name: "Cutural"},
   {id: 10, name: "Scientific"},
   {id: 11, name: "Geographic"},
   {id: 12, name: "Biology"},
   {id: 13, name: "History"},
   {id: 14, name: "Babies"}
]

const genreIds = [0,4,8,12];
const oddIds = [3,7,11]




function doSomething(indexes, odds, array) {
	array.forEach((value, index)  => {
   if (typeof(indexes.find(element => element == index)) !== 'undefined') {
        console.log('Inicia: ' + value.name);
    } else if(typeof(odds.find(element => element == index)) !== 'undefined') {        
       var rest = indexes.slice(1);
       console.log(value.name + ' termina.');
	} else {console.log(value.name);}
});
}


//moviesNamesAndGenres.forEach(function callback(value, index) {
 // console.log(`${index}: ${value}`);
//});

doSomething(genreIds, oddIds, moviesNamesAndGenres)