怎么输出数组的每一个值


  • 0

    const users = [
    {username:'Jerry',age:'21',gender:'male'},
    {username:'Tomy',age:'22',gender:'male'},
    {username:'Lily',age:'19',gender:'female'},
    {username:'Lucy',age:'20',gender:'female'}
    ]
    class Index extends Component{
    render(){
    for(let user of users){
    return(
    <div>
    <div>姓名:{user.username}</div>
    <div>年龄:{user.age}</div>
    <div>性别:{user.gender}</div>
    <div>姓名:{user.username}</div>
    <div>年龄:{user.age}</div>
    <div>性别:{user.gender}</div>
    <div>姓名:{user.username}</div>
    <div>年龄:{user.age}</div>
    <div>性别:{user.gender}</div>
    <div>姓名:{user.username}</div>
    <div>年龄:{user.age}</div>
    <div>性别:{user.gender}</div>
    </div>
    )
    }

    }
    }
    如果我只是想输出每一个数组下标的对象值


  • 0

    <div>
    {
    users.map((user,index) =>{
    return(
    <div>
    <div>下标:{index}</div>
    <div>对象:{user}</div>
    </div>
    )
    }
    }
    </div>


登录后回复
 

与 ScriptOJ 的连接断开,我们正在尝试重连,请耐心等待