Macro: Convert a list to an Array declaration

This is a simple macro to take a list of items, one item per line, and convert them into quoted items in an Array declaration suitable for many programming languages. I hope you find it useful.

List to Array.kmmacros (3.9 KB)

Here's how it works. Start with a list of items. Select the items.

red
orange
yellow
green
blue
indigo
violet

Trigger the macro. It cuts the text, formats the text, and pastes it in place.

["red","orange","yellow","green","blue","indigo","violet"]

That's it.

Given the way I've constructed the macro, it should be simple to substitute different declaration structures or quotation requirements.

Thanks for sharing.

IME, this is a very easy task in most languages.
##javascript for example:

var sourceStr = `red
orange
yellow
green
blue
indigo
violet`

var sourceList = sourceStr.split("\n")
sourceList

/*~~~ RESULTS ~~~
["red", "orange", "yellow", "green", "blue", "indigo", "violet"]
*/