Created
June 10, 2020 21:33
-
-
Save jonathanws/596a900280e43eb92fe60ea051f01bd4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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