【发布时间】:2018-09-16 05:09:24
【问题描述】:
所以今天我正在学习一些 ES6 数组助手,我想用它们来改变我现有的 for 循环,但是我不能得到与 for 循环相同的结果
function comment(){
let index;
for(let i = 0; i < commentArray.length; i++){
if(commentArray[i]._id == req.params.commentId){
index = commentArray.indexOf(commentArray[i]);
}
}
return index;
}
var com = comment();
它是nodejs,我正在尝试从数据库中获取元素索引,而不是从中提取,我的代码工作得很好,但我想用数组助手来改变它,我想我需要find helper,但我不能让它起作用!
【问题讨论】:
-
你的“数组助手”代码是什么?
标签: javascript arrays node.js ecmascript-6