Note that there are some explanatory texts on larger screens.

plurals
  1. POSplitting string of integers into array - elements don't get recognized
    primarykey
    data
    text
    <p>I am attempting to split a string of integers into an array in JavaScript.</p> <p>Originally I had: </p> <pre><code>m.rows[7] = new Array (8,11); </code></pre> <p>And I am changing it to: </p> <pre><code>var nearby = nearby.split(","); m.rows[7] = new Array (nearby); </code></pre> <p>(And setting a variable with the appropriate integers separated by a comma in my level editor. When I print "nearby[0]" to the console I get '8'. When I print "nearby[1]" to the console I get 11)</p> <p>However, I then have this code in which I attempt to match one of the elements in the array with an element in another array:</p> <pre><code> for (var i = m.rows[id].length-1; i &gt;= 0; i--) { // If the loop finds an element ID that matches the ID of the last element in the path array, do this: console.log('test nearby 2: ' + m.rows[id][i]); if (m.rows[id][i] == this.path_array[this.path_array.length-1].id) { // Loop through the one array for (var j = all_nodes.length-1; j &gt;= 0; j--){ // If the ID of one of one of these entities matches the id of the instance that was just clicked if (all_nodes[j].id == id) { // Activate that node: all_nodes[j].active = true; } } break; } </code></pre> <p>When I actually put "8,11" into the array above manually the above works perfectly. However when I attempt to use "nearby" which I split into the array, it does not. And printing it to the console in "test nearby 2" above, when I use "nearby" "8,11" gets printed. When I manually enter "8,11" into that array I get "11". </p> <p>I'm fairly new to JavaScript so I'm probably missing something extremely obvious here - can anyone shed some light? </p> <p>Thanks!</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload