I was wondering how to use -this- with a function parameter, in a JS object
How can i specify that -books- is going to be a value from the object when calling the function ?
res.write(tableGenerator.bookTable(data.sortBooks(data.englishBooks)));
const data = {
englishBooks: [
{
title: "The Fellowship of the Ring",
language: "English",
country: "United Kingdom",
author: "J.R.R. Tolkien",
date: "1954-07-29",
},
{
title: "Prelude to foundation",
language: "English",
country: "United States",
author: "Isaac Asimov",
date: "1988-11-08",
}
],
sortBooks(books) {
return books.sort(
(a, b) => a.date.substring(0, 4) - b.date.substring(0, 4)
);
},
};
Thanks !
I tried the code below :
res.write(tableGenerator.bookTable(data.sortBooks(englishBooks)));
sortBooks(books) {
return this.books.sort(
(a, b) => a.date.substring(0, 4) - b.date.substring(0, 4)
);
},