How to return multiple values from a function in JavaScript

Returning multiple values from a single function is a common requirement when processing data or performing calculations that yield several results. As the creator of CoreUI, a widely used open-source UI library, and with over 25 years of experience in software development, I’ve implemented countless functions that need to return multiple pieces of related data. The most effective approach is using array destructuring with return statements, which allows you to extract multiple values in a single, readable operation. This pattern provides clean syntax and maintains code clarity while avoiding the need for multiple function calls.

Return an array from your function and use destructuring assignment to extract multiple values cleanly.

function getCoordinates() {
  return [42.3601, -71.0589]
}

const [latitude, longitude] = getCoordinates()

The function returns an array containing multiple values, and destructuring assignment extracts them into individual variables in a single line. This approach is concise and maintains the order of returned values. You can also use object destructuring for named returns: return { lat: 42.3601, lng: -71.0589 } and destructure with const { lat, lng } = getCoordinates() for better semantic clarity.

Best Practice Note:

This is the same pattern we use in CoreUI utility functions for returning coordinate pairs, dimension calculations, and validation results. Use array destructuring when order matters, and object destructuring when you need named, self-documenting return values.


Speed up your responsive apps and websites with fully-featured, ready-to-use open-source admin panel templates—free to use and built for efficiency.


About the Author