Click a link to a string element in an array in a new array of strings

Given the following code:

    var old_Array =["One","Two","..."];
    var len = old_Array .length;
    var new_Array =[];
    for(var i=0;i<len;++i)
    {
      new_Array.push(old_Array [i]); // ----- [1]
    }

After line [1], new_Array lines are filled.

  • Is each element a reference to string elements in old_Array,or just copy each element of a string?
  • Does the translator optimize the javascript interpreter / compiler - [1] clicking links of each element of the string in old_Array?
+4
source share
2 answers

: - . , . ( , , .)

: , javascript [1], old_Array.

:

var new_Array = old_Array.slice();

.

0

. - , , , . ,

var s2 = s.substr(0, 3);

s2 , , ​​ s. , , . , , GC , , , .

, JS-. MDN .

0

Source: https://habr.com/ru/post/1685578/


All Articles