I have the following array of books. I want a write a function that receives the target book and the language, removes that book (key, value) from the nested object and returns the new array.
let books = [
{
language: 'spanish',
books: {
book_1: 'book1_spanish',
book_2: 'book2_spanish',
book_3: 'book3_spanish'
}
},
{
language: 'italian',
books: {
book_1: 'book1_italian',
book_2: 'book2_italian',
book_3: 'book3_italian'
}
}
];
let targetBook = { book_1: 'book1_spanish' };
let language = 'spanish';
I am stuck at looping over the nested object.
function removeTargetBook(lan, target) {
return books.map(book => {
if (book.language == lan) {
Object.values(book).map(value => {});
}
});
}
It should return the same array without book_1: 'book1_spanish'. This is my stackblitz: https://stackblitz.com/edit/js-yxcrbq
Thanks.
Via Active questions tagged javascript - Stack Overflow https://ift.tt/2FdjaAW
Comments
Post a Comment