我试图将文本转换为二进制文件,但是当我的循环运行时,它永远不会结束。我无法弄清楚为什么是这样。永不止于for循环
有没有更好的方法来做到这一点?
handleBinaryChange: function(e){
var friendsCopy = this.state.friendsArray;
for (var i = 0; i < friendsCopy.length; i++) {
for (var j = 0; j < friendsCopy[i].friendsName.length; j++) {
console.log(friendsCopy[i].friendsName += friendsCopy[i].friendsName[j].charCodeAt(0).toString(2) + " ");
}//End of 'j' for
}//End of 'i' for
this.setState({
friendsArray: friendsCopy //make friendsCopy contain the new value for friendsName
});
}
}
都将增加你的console.log语句friendsName,不是吗? – Icepickle
此外,它不是friendsArray的副本,它是对原始数组的另一个参考。 – ManoDestra
是不是将新值添加到前一个? – grgre