In a javascript array, how do I get the last 5 elements, excluding the first element?
我正在使用express/node。
我有
var texts = [{"id":1, "content":"one"}, {"id":2, "content":"two"},{"id":3, "content":"three", "id":4, "content":"four"];
在get请求中,我尝试如下响应:
app.get('/api/texts/', function (req, res, next) {
res.json(texts.slice(3, 1));
next();
});
编辑:
app.get('/api/texts/', function (req, res, next) {
res.json(texts);
next();
});
上面正确地打印出内部的所有元素
texts
res.json(texts.slice(3,1));
它打印出来了
[]
.