Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/reactjs/21.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 创建一个数组,直到reactjs中的任何特定数字_Javascript_Reactjs - Fatal编程技术网

Javascript 创建一个数组,直到reactjs中的任何特定数字

Javascript 创建一个数组,直到reactjs中的任何特定数字,javascript,reactjs,Javascript,Reactjs,我是React js的初学者,正在尝试做一些操作 我想创建一个数组,直到任意数组的长度(特定数字) 假设我的数组长度是10,那么数组应该是 我的状态变量- this.state{ length = 10, length_array= [] } handleClick = () =>{ this.setState{ length_array:[1,2,3,4,5,6,7,8,9,10] }} 我想在我的表头显示这个数组 <Table> <tr&

我是React js的初学者,正在尝试做一些操作

我想创建一个数组,直到任意数组的长度(特定数字) 假设我的数组长度是10,那么数组应该是

我的状态变量-

 this.state{
 length = 10,
 length_array= []
}

handleClick = () =>{
    this.setState{
    length_array:[1,2,3,4,5,6,7,8,9,10]
}}
我想在我的表头显示这个数组

<Table>
  <tr>
     <th>
         this.state.length_array.map((item, key) =>
         <th>{item.name}</th>
);
     </th>
  </tr>
</Table>

this.state.length_array.map((项,键)=>
{item.name}
);

谢谢。

对循环使用普通

函数createArraybyLength(长度){
设arr=[]

for(设i=1;i除了holydragon的答案之外,不使用for循环

const length=10;
常量arr=Array(10).fill(null).map((项,索引)=>index+1);

console.log(arr)
在您的掌上电脑中执行此操作

 handleClick = () =>{
     let newArray = []
    for(let i=1; i<=this.state.length; i++){
      newArray.push(i);
    }
    this.setState({
      length_array : newArray
    })
}}
handleClick=()=>{
让newArray=[]

对于(让i=1;i使用)您的代码充满了基本语法错误?