javascript console - array to text file
- User
javascript console - array to text file
Assistant
Here's how to save an array to a text file using JavaScript in the browser console:
javascriptfunction saveArrayToTextFile(array, filename) { // Convert array to string (each item on a new line) const text = array.join('\n'); // Create a Blob with the text content const blob = new Blob([text], { type: 'text/plain' }); // Create a URL for the Blob const url = URL.createObjectURL(blob); // Create a temporary anchor element const a = document.createElement('a'); a.href = url; a.download = filename || 'array-data.txt'; // Append to the document, click it, and remove it document.body.appendChild(a); a.click(); document.body.removeChild(a); // Release the URL object URL.revokeObjectURL(url); } // Example usage: const myArray = ['item1', 'item2', 'item3']; saveArrayToTextFile(myArray, 'my-array.txt');
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.