Convert table to csv using only JavaScript