Skip to content

Instantly share code, notes, and snippets.

@jonathanws
Created June 10, 2020 21:33
Show Gist options
  • Save jonathanws/596a900280e43eb92fe60ea051f01bd4 to your computer and use it in GitHub Desktop.
Save jonathanws/596a900280e43eb92fe60ea051f01bd4 to your computer and use it in GitHub Desktop.
const strings = ['boo', 'bar', 'biz', 'baz']
// piece everything together
console.log(strings.join()). // boo,bar,biz,baz
// or add a delimiter, like '\n'
console.log(strings.join('\n')) // boo\nbar\nbiz\baz
// find strings that match our condition
console.log(strings.filter((s) => s.includes('a'))) // [ 'bar', 'baz' ]
// or find just the first string that matches a condition
console.log(strings.find((s) => s.includes('a'))) // bar
// or if you start with one big delimited string and need an array to grep
const altogether = strings.join('\n')
console.log(altogether.split('\n')) // [ 'boo', 'bar', 'biz', 'baz' ] 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment