Object into Array
Convert object into a list of tuples representing the field and the value.
Before
const palette = {
apricot: "#f47868",
lightning: "#ffcd1c",
delta: "6f44f0",
};
After
const palette = [
["apricot", "#f47868"],
["lightning", "#ffcd1c"],
["delta", "6f44f0"],
];
Preview
Command
jmr{[mi[s:<enter>
r,bems"vt,ms[
- Go to the line below with
j
, this is because we need to be inside of the object for the next step. mr{[
replaces the nearest pair of curly braces "{" with square brackets "["mi[
selects inside the entire array- Use
s
to enter select mode, which searches inside our selection and creates sub-selections based on a pattern - Input
:
and then hit<enter>
, which will place a cursor on every ":" creating many single-width selections r,
replaces each selection with a ",". Essentially we've replaced each colon with a commabe
selects the previous word on each line and moves each cursor to the end of each wordms"
surrounds each word with double quotes to make stringsvt,
selects each line excluding the final commams[
surrounds each individual selection with "[" to turn it into an array