When JavaScript Goes ‘Splat’

T Mo
T Mo
Aug 13 · 2 min read
Photo by Patrick Tomasso on Unsplash

A Clever Tool

# With splat (*)
arr = [1, 2, 3]
method_call(*arr)
# Equivalent to:
method_call(arr[0], arr[1], arr[2])
# A.K.A:
method_call(1, 2, 3)
# As opposed to passing the whole array as a single argument:
method_call(arr)

When Would I Need This in JavaScript?

S…s…s…splat

var arr = [1, 2, 3];
var max = Math.max(…arr);

Let’s Wrap

Welcome to a place where words matter. On Medium, smart voices and original ideas take center stage - with no ads in sight. Watch
Follow all the topics you care about, and we’ll deliver the best stories for you to your homepage and inbox. Explore
Get unlimited access to the best stories on Medium — and support writers while you’re at it. Just $5/month. Upgrade