0

I'm using alasql to convert into CSV:

data = ["402 Fourth Avenue", "11 Russell Avenue", "East Diamond Avenue"];

function exportData(list) {
    alasql.promise('SELECT * INTO CSV("test.csv", {separator:" "} ) FROM ?',list)
     .then(function(data){
         console.log('Data saved');
    }).catch(function(err){
         console.log('Error:', err);
    });
}

When I pass it through the function my result ends up like this:

4 0 2   "F" "o" "u" "r" "t" "h"   "A" "v" "e" "n" "u" "e"

I cannot figure out why! Thank you in advance you will make my day!

1 Answer 1

2

Based on this example in the documentation, the argument should be a 3-dimensional array.

  • The first dimension corresponds to the placeholders (?) in the query.
  • The second dimension is the rows of the CSV.
  • The third dimension is the columns in the CSV.

So data should be a 2-dimensional array, and then you should wrap it in another array when calling alasql.

data = [["402 Fourth Avenue"], ["11 Russell Avenue"], ["East Diamond Avenue"]];

function exportData(list) {
    alasql.promise('SELECT * INTO CSV("test.csv", {separator:" "} ) FROM ?',[list])
     .then(function(data){
         console.log('Data saved');
    }).catch(function(err){
         console.log('Error:', err);
    });
}
Sign up to request clarification or add additional context in comments.

1 Comment

thank you!! My array wasn't up to snuff. Much appreciated!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.