Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to iterate over a javascript line delimited string, check the semi-colon delimited first value, and join lines where value is equal?
    primarykey
    data
    text
    <p>I have a CSV that I'm using as a data source. I need to split the lines on the newline character ('\n') into a variable called 'lines', and I need to split the semi-colon (';') delimited values in each line into a variable called 'items'.</p> <p>I want to be able to check the first value on a line and, if it equals the input value in an input box, I want to add this line, with the semi-colon delimiter between the values, to a new variable called newData. If it's not equal to the value in the input box, I want to exclude it.</p> <p>I basically want to filter out each line where the first value doesn't equal the value I'm searching for.</p> <p>Here's a sample of the data (assume a newline ('\n') character after each line):</p> <pre><code>"ID";"Date";"Time";"Status" "1";"2013.01.01";"10:03 AM";"Active" "1";"2013.01.05";"07:45 AM";"Active" "2";"2013.01.03";"9:12 PM";"Active" "2";"2013.01.11";"6:37 AM";"Inactive" "1";"2013.01.22";"12:57 PM";"Inactive" </code></pre> <p>I can split off the first header line and that won't be included in the results I'm seeking. If my search is on the ID column and the search value is 1, I want to only return the lines where the ID equals 1 and want it to match the format above (sans header line). Conversely, if the search value is 7, I would only return either no lines or just the header line.</p> <p>All I've been able to do so far is split the lines from the data I'm importing (all of this code I found, I'm really not that familiar with javascript or jQuery):</p> <pre><code>$.get("myFile.csv", function(data) { data = data.replace(/"/g, ""); var lines = data.split('\n'); var first = lines.shift().split(';'); }); // HTML Input Box &lt;input id="search_box" type="text"&gt; &lt;button id="btn_search"&gt;Search&lt;/button&gt; </code></pre> <p>Thanks.</p>
    singulars
    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.
 

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