title: How to split a string into an array in jQuery when there is only one element in the string?
body: <p>I have this code, that takes a string and splits it into an array:</p>
  
  <pre><code>nodes = $("#" + model_id + "-" + node_class + "--" + "title").data("nodes").split(",")
  </code></pre>
  
  <p>When there is only one element in the string (no commas), the variable "nodes" does not become an array, but a regular variable. So when I try to iterate over each element in "nodes", nothing happens if the original string only contains one element. If it has several elements, everything is OK.</p>
  
  <pre><code>$.each(nodes, function (id, node_id) {
    if ($("#" + model_id + "-" + node_class + "-" + node_id + "-" + "chkbx").is(":checked")) {
      counter ++
    }
  })
  </code></pre>
  
  <p>I have tried to declare "nodes" as an array, but when I assign the splitted string, it's all the same. Since I use a "split" to assign values I don't think I can use "push" to append values to the array.</p>
  
  <p>I have tried to put square brackets everywhere, I think, i.e. like this: </p>
  
  <pre><code>[nodes] = $("#" + model_id + "-" + node_class + "--" + "title").data("nodes").split(",")
  </code></pre>
  
  <p>... but that didn't help.</p>
  
  <p>Is there any solutions to this, except from checking if "nodes" is an array or not, and then write different code to handle both options?</p>