Skip to content

Array tools

Read · 1 of 3

Do something to every value

a.map(x => x * 2) makes a new array with every value doubled. a.filter(x => x > 0) keeps only the values that pass the test.

a.join(" ") turns an array into text with spaces between. a.slice(1, 3) copies positions 1 and 2. a.includes(x) checks if x is in it.

Printing an array with console.log shows brackets and extra spaces. Use join for clean output.