How to push all response’ ids except first id ? I mean below code pushes all ids to idList array. I want to push all ids again but except first id should not be pushed.How to edit below code ?
const getAllId = async () => {
let res = await axios({
method: "get",
url: "/v1/feed",
});
const idList = [];
res.feed.forEach((item) => {
idList.push(item.id);
});
return idList;
};
2
Answers
Use
.map
to transform an array to an array, and.slice()
to skip the first item inres.feed
.If you really want to use
forEach
and not slice the feed, use theindex
parameter it passes to the callback:Try This One Example