I have an array list of objects, and I only want to return the last 7 objects in the array. help pls
I have tried to use, filter, map and find, but I could not get the output I was expecting
var welcomeMessage = [{
from: "Clement",
text: "Welcome to Freeborn chat system!",
id: 0
},
{
from: "mark",
text: "Hello",
id: 1
},
{
from: "clement",
text: "welcome",
id: 2
},
{
from: "mark",
text: "long time",
id: 3
},
{
from: "clement",
text: "yeah, indeed",
id: 4
},
{
from: "mark",
text: "real good to be hear",
id: 5
},
{
from: "clement",
text: "you looking good",
id: 7
},
{
from: "mark",
text: "Hello",
id: 8
},
{
from: "clement",
text: "welcome",
id: 9
}
]
const messages = [welcomeMessage]
function latestMessage(messages, search) {
let search = rquest.body;
let messages = messages.length - 7
const messages.filter(message => {
return message
})
}