javascript / beginner
Snippet
Creating Lists with Array.join()
Array.join() creates and returns a new string by concatenating all elements in an array, separated by a specified separator string. It is the easiest way to display array data as a single line of text in your components.
snippet.js
1
2
3
4
function TagList(props) {const formattedTags = props.tags.join(' | ');return <p>Categories: ' + formattedTags + '</p>;}
nextjs
Breakdown
1
props.tags.join(' | ')
Takes each item in the array and puts the vertical bar character between them in the final string.