Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

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,t,;vgsms[lems"
  1. Go to the line below with j, this is because we need to be inside of the object for the next step.
  2. mr{[ replaces the nearest pair of curly braces "{" with square brackets "["
  3. mi[ selects inside the entire array
  4. Use s to enter select mode, which searches inside our selection and creates sub-selections based on a pattern
  5. Input : and then hit <enter>, which will place a cursor on every ":" creating many single-width selections
  6. r, replaces each selection with a ",". Essentially we've replaced each colon with a comma
  7. t, moves the cursor on each line to the ending comma
  8. ; collapses the selection around each cursor into a single selection
  9. vgs selects each line excluding the final comma
  10. ms[ surrounds each individual selection with "[" to turn it into an array. We're almost done here. We just need to transform the first item in each sub-array into a string.
  11. l moves 1 character forward, replacing the selection with just a 1-width selection
  12. e selects until the end of each word. Since we start at the first character and select until the end, this selects the entire word.
  13. ms" surrounds each word with double quotes to make strings