Populating another array from array - Javascript

后端 未结 8 1589
我寻月下人不归
我寻月下人不归 2020-12-29 22:12

Very simple thing I am trying to do in JS (assign the values of one array to another), but somehow the array bar\'s value doesn\'t seem affected at all.

<
相关标签:
8条回答
  • 2020-12-29 22:55

    copy-or-clone-javascript-array-object

    var a = [ 'apple', 'orange', 'grape' ];
     b = a.slice(0);
    
    0 讨论(0)
  • 2020-12-29 22:59

    You have two problems:

    First you need to initialize bar as an array:

    var bar = [];
    

    Then arr should be ar in here:

    for(i=0;i<arr.length;i++){
    

    Then you'll get alerted your banana :)

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