【发布时间】:2020-03-09 17:25:54
【问题描述】:
我正在申请。例如,我尝试在以下代码中打印字母“a”16 次。但它没有用。这是因为我确实使用了“return”。我知道。但它不使用错误。如何将字母“a”打印 16 次?
import React from "react";
import Game from "./game";
class App extends React.Component {
constructor(props) {
super(props);
this.Game = new Game();
console.log(this.Game.play());
}
draw = () => {
for (let a = 0; a < 4; a++) {
for (let b = 0; b < 4; b++) {
return <div>a</div>;
}
}
};
componentDidMount = () => {
this.draw();
};
render() {
return (
<div>
<h2>2048 Game With React</h2>
<p>{this.draw()}</p>
</div>
);
}
}
export default App;
【问题讨论】:
-
第一个
return中止整个循环。
标签: javascript arrays reactjs react-native react-router