Javascript pushing object into array

前端 未结 4 2393
無奈伤痛
無奈伤痛 2021-02-20 05:26

Hey, I currently am having trouble trying to get this to work. Here\'s a sample code of what I am trying. A lot has been taken out, but this should still contain the problem. I

相关标签:
4条回答
  • 2021-02-20 06:15

    I would do

    player = [];
    

    instead of

    player = new array();
    

    As a sanity check, try doing:

    document.write("Name: " + player[0].name);
    
    0 讨论(0)
  • 2021-02-20 06:18

    I tried this and worked:

    player = [{}];
    

    instead of:

    player = new Array();
    
    0 讨论(0)
  • 2021-02-20 06:19

    You have a typo in your code.

    Change

    player = new array();
    

    to

    player = new Array();
    
    0 讨论(0)
  • 2021-02-20 06:26

    Well, you've got an error. It's not array but Array.

    0 讨论(0)
提交回复
热议问题