Why do I need to copy an array to use a method on it?











up vote
15
down vote

favorite












I can use Array() to have an array with a fixed number of undefined entries. For example



Array(2); // [empty × 2] 


But if I go and use the map method, say, on my new array, the entries are still undefined:



Array(2).map( () => "foo");  // [empty × 2] 


If I copy the array then map does work:



[...Array(2)].map( () => "foo");  // ["foo", "foo"]


Why do I need a copy to use the array?










share|improve this question






















  • what is the result of [...Array(2)]
    – Kain0_0
    Nov 27 at 2:39










  • @Kain0_0 It is [undefined, undefined]. And Array.isArray(Array(2)) is true.
    – cham
    Nov 27 at 2:41






  • 1




    Can use fill() also. Array(2).fill("foo"); // ["foo", "foo"] Just have to be careful with passing object to fill as all elements will be same reference
    – charlietfl
    Nov 27 at 2:54

















up vote
15
down vote

favorite












I can use Array() to have an array with a fixed number of undefined entries. For example



Array(2); // [empty × 2] 


But if I go and use the map method, say, on my new array, the entries are still undefined:



Array(2).map( () => "foo");  // [empty × 2] 


If I copy the array then map does work:



[...Array(2)].map( () => "foo");  // ["foo", "foo"]


Why do I need a copy to use the array?










share|improve this question






















  • what is the result of [...Array(2)]
    – Kain0_0
    Nov 27 at 2:39










  • @Kain0_0 It is [undefined, undefined]. And Array.isArray(Array(2)) is true.
    – cham
    Nov 27 at 2:41






  • 1




    Can use fill() also. Array(2).fill("foo"); // ["foo", "foo"] Just have to be careful with passing object to fill as all elements will be same reference
    – charlietfl
    Nov 27 at 2:54















up vote
15
down vote

favorite









up vote
15
down vote

favorite











I can use Array() to have an array with a fixed number of undefined entries. For example



Array(2); // [empty × 2] 


But if I go and use the map method, say, on my new array, the entries are still undefined:



Array(2).map( () => "foo");  // [empty × 2] 


If I copy the array then map does work:



[...Array(2)].map( () => "foo");  // ["foo", "foo"]


Why do I need a copy to use the array?










share|improve this question













I can use Array() to have an array with a fixed number of undefined entries. For example



Array(2); // [empty × 2] 


But if I go and use the map method, say, on my new array, the entries are still undefined:



Array(2).map( () => "foo");  // [empty × 2] 


If I copy the array then map does work:



[...Array(2)].map( () => "foo");  // ["foo", "foo"]


Why do I need a copy to use the array?







javascript arrays






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Nov 27 at 2:35









cham

576621




576621












  • what is the result of [...Array(2)]
    – Kain0_0
    Nov 27 at 2:39










  • @Kain0_0 It is [undefined, undefined]. And Array.isArray(Array(2)) is true.
    – cham
    Nov 27 at 2:41






  • 1




    Can use fill() also. Array(2).fill("foo"); // ["foo", "foo"] Just have to be careful with passing object to fill as all elements will be same reference
    – charlietfl
    Nov 27 at 2:54




















  • what is the result of [...Array(2)]
    – Kain0_0
    Nov 27 at 2:39










  • @Kain0_0 It is [undefined, undefined]. And Array.isArray(Array(2)) is true.
    – cham
    Nov 27 at 2:41






  • 1




    Can use fill() also. Array(2).fill("foo"); // ["foo", "foo"] Just have to be careful with passing object to fill as all elements will be same reference
    – charlietfl
    Nov 27 at 2:54


















what is the result of [...Array(2)]
– Kain0_0
Nov 27 at 2:39




what is the result of [...Array(2)]
– Kain0_0
Nov 27 at 2:39












@Kain0_0 It is [undefined, undefined]. And Array.isArray(Array(2)) is true.
– cham
Nov 27 at 2:41




@Kain0_0 It is [undefined, undefined]. And Array.isArray(Array(2)) is true.
– cham
Nov 27 at 2:41




1




1




Can use fill() also. Array(2).fill("foo"); // ["foo", "foo"] Just have to be careful with passing object to fill as all elements will be same reference
– charlietfl
Nov 27 at 2:54






Can use fill() also. Array(2).fill("foo"); // ["foo", "foo"] Just have to be careful with passing object to fill as all elements will be same reference
– charlietfl
Nov 27 at 2:54














3 Answers
3






active

oldest

votes

















up vote
24
down vote



accepted










When you use Array(arrayLength) to create an array, you will have:




a new JavaScript array with its length property set to that number (Note: this implies an array of arrayLength empty slots, not slots with actual undefined values).




The array does not actually contain any values, not even undefined values - it simply has a length property.



When you spread an item with a length property into an array, eg [...{ length: 4 }], spread syntax accesses each index and sets the value at that index in the new array. For example:






const arr1 = ;
arr1.length = 4;
// arr1 does not actually have any index properties:
console.log('1' in arr1);

const arr2 = [...arr1];
console.log(arr2);
console.log('2' in arr2);





And .map only maps properties/values for which the property actually exists in the array you're mapping over.



Using the array constructor is confusing. I would suggest using Array.from instead, when creating arrays from scratch - you can pass it an object with a length property, as well as a mapping function:






const arr = Array.from(
{ length: 2 },
() => 'foo'
);
console.log(arr);








share|improve this answer





















  • I saw Array() in a course and it reminded me of something useful in Python, But sadly it's maybe it's not so useful. Cheers.
    – cham
    Nov 27 at 2:45












  • It used to be a decent option, before Array.from was available, but now I don't think there's any reason to use it, it has too much potential for confusion.
    – CertainPerformance
    Nov 27 at 2:46


















up vote
7
down vote













The reason is that the array element is unassigned. See here the first paragraph of the description. ... callback is invoked only for indexes of the array which have assigned values, including undefined.



Consider:



var array1 = Array(2);
array1[0] = undefined;

// pass a function to map
const map1 = array1.map(x => x * 2);

console.log(array1);
console.log(map1);


Outputs:



Array [undefined, undefined]
Array [NaN, undefined]


When the array is printed each of its elements are interrogated. The first has been assigned undefined the other is defaulted to undefined.



The mapping operation calls the mapping operation for the first element because it has been defined (through assignment). It does not call the mapping operation for the second argument, and simply passes out undefined.






share|improve this answer








New contributor




Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.

























    up vote
    0
    down vote













    As pointed out by @CertainPerformance, your array doesn't have any properties besides its length, you can verify that with this line: new Array(1).hasOwnProperty(0), which returns false.



    Looking at 15.4.4.19 Array.prototype.map you can see, at 7.3, there's a check whether a key exists in the array.



    1..6. [...]

    7. Repeat,
    while k < len





    1. Let
      Pk be ToString(k).





    2. Let
      kPresent be the result of calling the [[HasProperty]]
      internal method of O with argument Pk.




    3. If
      kPresent is true, then



      1. Let
        kValue be the result of calling the [[Get]] internal
        method of O with argument Pk.





      2. Let
        mappedValue be the result of calling the [[Call]] internal
        method of callbackfn with T as the this
        value and argument list containing kValue, k, and
        O.





      3. Call
        the [[DefineOwnProperty]] internal method of A with
        arguments Pk, Property Descriptor {[[Value]]: mappedValue,
        [[Writable]]: true, [[Enumerable]]: true,
        [[Configurable]]: true}, and false.







    4. Increase
      k by 1.




    9. Return A.




    share|improve this answer





















      Your Answer






      StackExchange.ifUsing("editor", function () {
      StackExchange.using("externalEditor", function () {
      StackExchange.using("snippets", function () {
      StackExchange.snippets.init();
      });
      });
      }, "code-snippets");

      StackExchange.ready(function() {
      var channelOptions = {
      tags: "".split(" "),
      id: "1"
      };
      initTagRenderer("".split(" "), "".split(" "), channelOptions);

      StackExchange.using("externalEditor", function() {
      // Have to fire editor after snippets, if snippets enabled
      if (StackExchange.settings.snippets.snippetsEnabled) {
      StackExchange.using("snippets", function() {
      createEditor();
      });
      }
      else {
      createEditor();
      }
      });

      function createEditor() {
      StackExchange.prepareEditor({
      heartbeatType: 'answer',
      convertImagesToLinks: true,
      noModals: true,
      showLowRepImageUploadWarning: true,
      reputationToPostImages: 10,
      bindNavPrevention: true,
      postfix: "",
      imageUploader: {
      brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
      contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
      allowUrls: true
      },
      onDemand: true,
      discardSelector: ".discard-answer"
      ,immediatelyShowMarkdownHelp:true
      });


      }
      });














      draft saved

      draft discarded


















      StackExchange.ready(
      function () {
      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491943%2fwhy-do-i-need-to-copy-an-array-to-use-a-method-on-it%23new-answer', 'question_page');
      }
      );

      Post as a guest















      Required, but never shown

























      3 Answers
      3






      active

      oldest

      votes








      3 Answers
      3






      active

      oldest

      votes









      active

      oldest

      votes






      active

      oldest

      votes








      up vote
      24
      down vote



      accepted










      When you use Array(arrayLength) to create an array, you will have:




      a new JavaScript array with its length property set to that number (Note: this implies an array of arrayLength empty slots, not slots with actual undefined values).




      The array does not actually contain any values, not even undefined values - it simply has a length property.



      When you spread an item with a length property into an array, eg [...{ length: 4 }], spread syntax accesses each index and sets the value at that index in the new array. For example:






      const arr1 = ;
      arr1.length = 4;
      // arr1 does not actually have any index properties:
      console.log('1' in arr1);

      const arr2 = [...arr1];
      console.log(arr2);
      console.log('2' in arr2);





      And .map only maps properties/values for which the property actually exists in the array you're mapping over.



      Using the array constructor is confusing. I would suggest using Array.from instead, when creating arrays from scratch - you can pass it an object with a length property, as well as a mapping function:






      const arr = Array.from(
      { length: 2 },
      () => 'foo'
      );
      console.log(arr);








      share|improve this answer





















      • I saw Array() in a course and it reminded me of something useful in Python, But sadly it's maybe it's not so useful. Cheers.
        – cham
        Nov 27 at 2:45












      • It used to be a decent option, before Array.from was available, but now I don't think there's any reason to use it, it has too much potential for confusion.
        – CertainPerformance
        Nov 27 at 2:46















      up vote
      24
      down vote



      accepted










      When you use Array(arrayLength) to create an array, you will have:




      a new JavaScript array with its length property set to that number (Note: this implies an array of arrayLength empty slots, not slots with actual undefined values).




      The array does not actually contain any values, not even undefined values - it simply has a length property.



      When you spread an item with a length property into an array, eg [...{ length: 4 }], spread syntax accesses each index and sets the value at that index in the new array. For example:






      const arr1 = ;
      arr1.length = 4;
      // arr1 does not actually have any index properties:
      console.log('1' in arr1);

      const arr2 = [...arr1];
      console.log(arr2);
      console.log('2' in arr2);





      And .map only maps properties/values for which the property actually exists in the array you're mapping over.



      Using the array constructor is confusing. I would suggest using Array.from instead, when creating arrays from scratch - you can pass it an object with a length property, as well as a mapping function:






      const arr = Array.from(
      { length: 2 },
      () => 'foo'
      );
      console.log(arr);








      share|improve this answer





















      • I saw Array() in a course and it reminded me of something useful in Python, But sadly it's maybe it's not so useful. Cheers.
        – cham
        Nov 27 at 2:45












      • It used to be a decent option, before Array.from was available, but now I don't think there's any reason to use it, it has too much potential for confusion.
        – CertainPerformance
        Nov 27 at 2:46













      up vote
      24
      down vote



      accepted







      up vote
      24
      down vote



      accepted






      When you use Array(arrayLength) to create an array, you will have:




      a new JavaScript array with its length property set to that number (Note: this implies an array of arrayLength empty slots, not slots with actual undefined values).




      The array does not actually contain any values, not even undefined values - it simply has a length property.



      When you spread an item with a length property into an array, eg [...{ length: 4 }], spread syntax accesses each index and sets the value at that index in the new array. For example:






      const arr1 = ;
      arr1.length = 4;
      // arr1 does not actually have any index properties:
      console.log('1' in arr1);

      const arr2 = [...arr1];
      console.log(arr2);
      console.log('2' in arr2);





      And .map only maps properties/values for which the property actually exists in the array you're mapping over.



      Using the array constructor is confusing. I would suggest using Array.from instead, when creating arrays from scratch - you can pass it an object with a length property, as well as a mapping function:






      const arr = Array.from(
      { length: 2 },
      () => 'foo'
      );
      console.log(arr);








      share|improve this answer












      When you use Array(arrayLength) to create an array, you will have:




      a new JavaScript array with its length property set to that number (Note: this implies an array of arrayLength empty slots, not slots with actual undefined values).




      The array does not actually contain any values, not even undefined values - it simply has a length property.



      When you spread an item with a length property into an array, eg [...{ length: 4 }], spread syntax accesses each index and sets the value at that index in the new array. For example:






      const arr1 = ;
      arr1.length = 4;
      // arr1 does not actually have any index properties:
      console.log('1' in arr1);

      const arr2 = [...arr1];
      console.log(arr2);
      console.log('2' in arr2);





      And .map only maps properties/values for which the property actually exists in the array you're mapping over.



      Using the array constructor is confusing. I would suggest using Array.from instead, when creating arrays from scratch - you can pass it an object with a length property, as well as a mapping function:






      const arr = Array.from(
      { length: 2 },
      () => 'foo'
      );
      console.log(arr);








      const arr1 = ;
      arr1.length = 4;
      // arr1 does not actually have any index properties:
      console.log('1' in arr1);

      const arr2 = [...arr1];
      console.log(arr2);
      console.log('2' in arr2);





      const arr1 = ;
      arr1.length = 4;
      // arr1 does not actually have any index properties:
      console.log('1' in arr1);

      const arr2 = [...arr1];
      console.log(arr2);
      console.log('2' in arr2);





      const arr = Array.from(
      { length: 2 },
      () => 'foo'
      );
      console.log(arr);





      const arr = Array.from(
      { length: 2 },
      () => 'foo'
      );
      console.log(arr);






      share|improve this answer












      share|improve this answer



      share|improve this answer










      answered Nov 27 at 2:42









      CertainPerformance

      68.2k143353




      68.2k143353












      • I saw Array() in a course and it reminded me of something useful in Python, But sadly it's maybe it's not so useful. Cheers.
        – cham
        Nov 27 at 2:45












      • It used to be a decent option, before Array.from was available, but now I don't think there's any reason to use it, it has too much potential for confusion.
        – CertainPerformance
        Nov 27 at 2:46


















      • I saw Array() in a course and it reminded me of something useful in Python, But sadly it's maybe it's not so useful. Cheers.
        – cham
        Nov 27 at 2:45












      • It used to be a decent option, before Array.from was available, but now I don't think there's any reason to use it, it has too much potential for confusion.
        – CertainPerformance
        Nov 27 at 2:46
















      I saw Array() in a course and it reminded me of something useful in Python, But sadly it's maybe it's not so useful. Cheers.
      – cham
      Nov 27 at 2:45






      I saw Array() in a course and it reminded me of something useful in Python, But sadly it's maybe it's not so useful. Cheers.
      – cham
      Nov 27 at 2:45














      It used to be a decent option, before Array.from was available, but now I don't think there's any reason to use it, it has too much potential for confusion.
      – CertainPerformance
      Nov 27 at 2:46




      It used to be a decent option, before Array.from was available, but now I don't think there's any reason to use it, it has too much potential for confusion.
      – CertainPerformance
      Nov 27 at 2:46












      up vote
      7
      down vote













      The reason is that the array element is unassigned. See here the first paragraph of the description. ... callback is invoked only for indexes of the array which have assigned values, including undefined.



      Consider:



      var array1 = Array(2);
      array1[0] = undefined;

      // pass a function to map
      const map1 = array1.map(x => x * 2);

      console.log(array1);
      console.log(map1);


      Outputs:



      Array [undefined, undefined]
      Array [NaN, undefined]


      When the array is printed each of its elements are interrogated. The first has been assigned undefined the other is defaulted to undefined.



      The mapping operation calls the mapping operation for the first element because it has been defined (through assignment). It does not call the mapping operation for the second argument, and simply passes out undefined.






      share|improve this answer








      New contributor




      Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
      Check out our Code of Conduct.






















        up vote
        7
        down vote













        The reason is that the array element is unassigned. See here the first paragraph of the description. ... callback is invoked only for indexes of the array which have assigned values, including undefined.



        Consider:



        var array1 = Array(2);
        array1[0] = undefined;

        // pass a function to map
        const map1 = array1.map(x => x * 2);

        console.log(array1);
        console.log(map1);


        Outputs:



        Array [undefined, undefined]
        Array [NaN, undefined]


        When the array is printed each of its elements are interrogated. The first has been assigned undefined the other is defaulted to undefined.



        The mapping operation calls the mapping operation for the first element because it has been defined (through assignment). It does not call the mapping operation for the second argument, and simply passes out undefined.






        share|improve this answer








        New contributor




        Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
        Check out our Code of Conduct.




















          up vote
          7
          down vote










          up vote
          7
          down vote









          The reason is that the array element is unassigned. See here the first paragraph of the description. ... callback is invoked only for indexes of the array which have assigned values, including undefined.



          Consider:



          var array1 = Array(2);
          array1[0] = undefined;

          // pass a function to map
          const map1 = array1.map(x => x * 2);

          console.log(array1);
          console.log(map1);


          Outputs:



          Array [undefined, undefined]
          Array [NaN, undefined]


          When the array is printed each of its elements are interrogated. The first has been assigned undefined the other is defaulted to undefined.



          The mapping operation calls the mapping operation for the first element because it has been defined (through assignment). It does not call the mapping operation for the second argument, and simply passes out undefined.






          share|improve this answer








          New contributor




          Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          The reason is that the array element is unassigned. See here the first paragraph of the description. ... callback is invoked only for indexes of the array which have assigned values, including undefined.



          Consider:



          var array1 = Array(2);
          array1[0] = undefined;

          // pass a function to map
          const map1 = array1.map(x => x * 2);

          console.log(array1);
          console.log(map1);


          Outputs:



          Array [undefined, undefined]
          Array [NaN, undefined]


          When the array is printed each of its elements are interrogated. The first has been assigned undefined the other is defaulted to undefined.



          The mapping operation calls the mapping operation for the first element because it has been defined (through assignment). It does not call the mapping operation for the second argument, and simply passes out undefined.







          share|improve this answer








          New contributor




          Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          share|improve this answer



          share|improve this answer






          New contributor




          Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.









          answered Nov 27 at 2:54









          Kain0_0

          2042




          2042




          New contributor




          Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.





          New contributor





          Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






          Kain0_0 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
          Check out our Code of Conduct.






















              up vote
              0
              down vote













              As pointed out by @CertainPerformance, your array doesn't have any properties besides its length, you can verify that with this line: new Array(1).hasOwnProperty(0), which returns false.



              Looking at 15.4.4.19 Array.prototype.map you can see, at 7.3, there's a check whether a key exists in the array.



              1..6. [...]

              7. Repeat,
              while k < len





              1. Let
                Pk be ToString(k).





              2. Let
                kPresent be the result of calling the [[HasProperty]]
                internal method of O with argument Pk.




              3. If
                kPresent is true, then



                1. Let
                  kValue be the result of calling the [[Get]] internal
                  method of O with argument Pk.





                2. Let
                  mappedValue be the result of calling the [[Call]] internal
                  method of callbackfn with T as the this
                  value and argument list containing kValue, k, and
                  O.





                3. Call
                  the [[DefineOwnProperty]] internal method of A with
                  arguments Pk, Property Descriptor {[[Value]]: mappedValue,
                  [[Writable]]: true, [[Enumerable]]: true,
                  [[Configurable]]: true}, and false.







              4. Increase
                k by 1.




              9. Return A.




              share|improve this answer

























                up vote
                0
                down vote













                As pointed out by @CertainPerformance, your array doesn't have any properties besides its length, you can verify that with this line: new Array(1).hasOwnProperty(0), which returns false.



                Looking at 15.4.4.19 Array.prototype.map you can see, at 7.3, there's a check whether a key exists in the array.



                1..6. [...]

                7. Repeat,
                while k < len





                1. Let
                  Pk be ToString(k).





                2. Let
                  kPresent be the result of calling the [[HasProperty]]
                  internal method of O with argument Pk.




                3. If
                  kPresent is true, then



                  1. Let
                    kValue be the result of calling the [[Get]] internal
                    method of O with argument Pk.





                  2. Let
                    mappedValue be the result of calling the [[Call]] internal
                    method of callbackfn with T as the this
                    value and argument list containing kValue, k, and
                    O.





                  3. Call
                    the [[DefineOwnProperty]] internal method of A with
                    arguments Pk, Property Descriptor {[[Value]]: mappedValue,
                    [[Writable]]: true, [[Enumerable]]: true,
                    [[Configurable]]: true}, and false.







                4. Increase
                  k by 1.




                9. Return A.




                share|improve this answer























                  up vote
                  0
                  down vote










                  up vote
                  0
                  down vote









                  As pointed out by @CertainPerformance, your array doesn't have any properties besides its length, you can verify that with this line: new Array(1).hasOwnProperty(0), which returns false.



                  Looking at 15.4.4.19 Array.prototype.map you can see, at 7.3, there's a check whether a key exists in the array.



                  1..6. [...]

                  7. Repeat,
                  while k < len





                  1. Let
                    Pk be ToString(k).





                  2. Let
                    kPresent be the result of calling the [[HasProperty]]
                    internal method of O with argument Pk.




                  3. If
                    kPresent is true, then



                    1. Let
                      kValue be the result of calling the [[Get]] internal
                      method of O with argument Pk.





                    2. Let
                      mappedValue be the result of calling the [[Call]] internal
                      method of callbackfn with T as the this
                      value and argument list containing kValue, k, and
                      O.





                    3. Call
                      the [[DefineOwnProperty]] internal method of A with
                      arguments Pk, Property Descriptor {[[Value]]: mappedValue,
                      [[Writable]]: true, [[Enumerable]]: true,
                      [[Configurable]]: true}, and false.







                  4. Increase
                    k by 1.




                  9. Return A.




                  share|improve this answer












                  As pointed out by @CertainPerformance, your array doesn't have any properties besides its length, you can verify that with this line: new Array(1).hasOwnProperty(0), which returns false.



                  Looking at 15.4.4.19 Array.prototype.map you can see, at 7.3, there's a check whether a key exists in the array.



                  1..6. [...]

                  7. Repeat,
                  while k < len





                  1. Let
                    Pk be ToString(k).





                  2. Let
                    kPresent be the result of calling the [[HasProperty]]
                    internal method of O with argument Pk.




                  3. If
                    kPresent is true, then



                    1. Let
                      kValue be the result of calling the [[Get]] internal
                      method of O with argument Pk.





                    2. Let
                      mappedValue be the result of calling the [[Call]] internal
                      method of callbackfn with T as the this
                      value and argument list containing kValue, k, and
                      O.





                    3. Call
                      the [[DefineOwnProperty]] internal method of A with
                      arguments Pk, Property Descriptor {[[Value]]: mappedValue,
                      [[Writable]]: true, [[Enumerable]]: true,
                      [[Configurable]]: true}, and false.







                  4. Increase
                    k by 1.




                  9. Return A.





                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Nov 27 at 8:59









                  Moritz Roessler

                  6,2571646




                  6,2571646






























                      draft saved

                      draft discarded




















































                      Thanks for contributing an answer to Stack Overflow!


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.





                      Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                      Please pay close attention to the following guidance:


                      • Please be sure to answer the question. Provide details and share your research!

                      But avoid



                      • Asking for help, clarification, or responding to other answers.

                      • Making statements based on opinion; back them up with references or personal experience.


                      To learn more, see our tips on writing great answers.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function () {
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53491943%2fwhy-do-i-need-to-copy-an-array-to-use-a-method-on-it%23new-answer', 'question_page');
                      }
                      );

                      Post as a guest















                      Required, but never shown





















































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown

































                      Required, but never shown














                      Required, but never shown












                      Required, but never shown







                      Required, but never shown







                      Popular posts from this blog

                      AnyDesk - Fatal Program Failure

                      How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

                      QoS: MAC-Priority for clients behind a repeater