If you want to map objects to something (in this case a property). I think Array.prototype.map is what you're looking for if you want to code functionally.

(fiddle)

If you want to support older browsers, that are not ES5 compliant you can shim it (there is a polyfill on the MDN page above). Another alternative would be to use underscorejs's pluck method:

var users = [
      {name: "Joe", age: 22},
      {name: "Kevin", age: 24},
      {name: "Peter", age: 21}
    ];
var result = _.pluck(users,'name').join(",")
Answer from Benjamin Gruenbaum on Stack Overflow
🌐
Codemzy
codemzy.com › blog › array-join-object-property
Using Array join() on an object property - Codemzy's Blog
May 30, 2023 - I've added a space after the comma by passing a string (", ") to .join() to use as the separator. Let's break that down so it's really clear what is happening at each stage. // the array of objects let names = [ { first: "Roger", last: "McRogerson" }, { first: "Peter", last: "Peterson" }, { first: "Jane", last: "Janeson" } ]; // create an array of the property values you need as strings let namesValues = names.map((name) => `${name.first} ${name.last}`); console.log(namesValues); // ["Roger McRogerson", "Peter Peterson", "Jane Janeson"] // join them to become a string with a comma separator let joinedNames = namesValues.join(", "); console.log(joinedNames); // "Roger McRogerson, Peter Peterson, Jane Janeson"
Discussions

javascript - jQuery Join Object Values - Stack Overflow
I am trying to join the values of an object/associative array to make changes to my code easier but I can't figure out how to properly join them. Here is my code: $( document ).on( "click", ".task... More on stackoverflow.com
🌐 stackoverflow.com
javascript - How to join values of one object? - Stack Overflow
The ',' in your join is not needed because that's the default value. 2017-11-02T07:28:22.577Z+00:00 ... @Werner Thank you for the remark. I just keep the ',' to make things clear 2017-11-02T07:36:38.627Z+00:00 ... You can use Object.values to get an array of the properties of your object, then ... More on stackoverflow.com
🌐 stackoverflow.com
November 2, 2017
javascript - Combine object key values into single string with separator - Stack Overflow
Update: Object.entries(obj) now supports in Mobile Safari Also ... Sign up to request clarification or add additional context in comments. ... You can use Array#map method along with Array#join method. Where Array#filter method can be used for filtering non-empty and defined property values. More on stackoverflow.com
🌐 stackoverflow.com
July 18, 2018
javascript - join() for object properties? - Stack Overflow
Just a side note, Object.entries() browser compatibility is very low. Nice solution though! 2017-08-10T08:55:34.483Z+00:00 ... Since the question is tagged with node.js I don't see it as a problem. 2017-08-10T08:57:57.057Z+00:00 ... Find the answer to your question by asking. Ask question ... See similar questions with these tags. ... Help me join ... More on stackoverflow.com
🌐 stackoverflow.com
August 10, 2017
People also ask

What is the most efficient way to join object properties in JavaScript?
A: Using Array.prototype.map() followed by .join() is typically the most efficient and readable method.
🌐
sqlpey.com
sqlpey.com › javascript › top-4-ways-to-join-values-from-array-of-objects-in-javascript
Top 4 Ways to Join Values from an Array of Objects in JavaScript
Can I join properties from objects that are deeply nested?
A: Yes, you can access nested properties using dot notation or bracket notation within the map() function.
🌐
sqlpey.com
sqlpey.com › javascript › top-4-ways-to-join-values-from-array-of-objects-in-javascript
Top 4 Ways to Join Values from an Array of Objects in JavaScript
What if there's a possibility of undefined values?
A: You can filter out undefined values during the mapping process with a simple condition.
🌐
sqlpey.com
sqlpey.com › javascript › top-4-ways-to-join-values-from-array-of-objects-in-javascript
Top 4 Ways to Join Values from an Array of Objects in JavaScript
🌐
GitHub
gist.github.com › lucasdavila › 4331999
Joining javascript key-value objects as string. · GitHub
Joining javascript key-value objects as string. GitHub Gist: instantly share code, notes, and snippets.
🌐
EyeHunts
tutorial.eyehunts.com › home › javascript join the array of objects | example code
JavaScript join the array of objects | Example code
August 19, 2022 - ["Joe", "Kevin", "Peter"].join(", ") // => "Joe, Kevin, Peter" If you want to perform a similar operation on a value held within it.
🌐
JavaScript Tutorial
javascripttutorial.net › home › javascript merge objects
How to Merge Objects in JavaScript
March 29, 2020 - The following example uses the spread operator (...) to merge the person and job objects into the employee object: let person = { firstName: 'John', lastName: 'Doe', age: 25, ssn: '123-456-2356' }; let job = { jobTitle: 'JavaScript Developer', location: 'USA' }; let employee = { ...person, ...job }; console.log(employee); Copy
Find elsewhere
🌐
SitePoint
sitepoint.com › blog › javascript › how to merge objects in javascript
How to Merge Objects in JavaScript — SitePoint
November 5, 2024 - Learn how to merge any object in JavaScript with the spread ( ... ) operator, Object.assign() method, and JSON stringify and parse methods.
🌐
Codegive
codegive.com › blog › js_object_join_values.php
JS Object Join Values: Master Efficient Data Manipulation & Unleash Hidden Potential!
The phrase "js object join values" refers to the process of extracting one or more values from a JavaScript object and then concatenating or combining them into a single string or a new data structure. Unlike arrays, which have a built-in join() method, objects do not directly support this ...
🌐
sqlpey
sqlpey.com › javascript › top-4-ways-to-join-values-from-array-of-objects-in-javascript
Top 4 Ways to Join Values from an Array of Objects in JavaScript
November 23, 2024 - A: Using Array.prototype.map() followed by .join() is typically the most efficient and readable method. A: Yes, you can access nested properties using dot notation or bracket notation within the map() function. A: You can filter out undefined values during the mapping process with a simple condition.
🌐
xjavascript
xjavascript.com › blog › perform-join-on-value-in-array-of-objects
How to Perform .join() on Values in an Array of Objects by Property in JavaScript — xjavascript.com
Joining values from an array of objects by property is a common task in JavaScript, and the solution is surprisingly simple: use map() to extract the property values into a primitive array, then join() to combine them into a string.
🌐
Mastering JS
masteringjs.io › tutorials › fundamentals › merge-two-objects
How to Merge Two Objects in JavaScript - Mastering JS
April 29, 2022 - const target = {a: 1, b: 2, c: 3}; const source = {d: 4, e: 5, f: 6}; Object.assign(target, source); target; // {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6}
🌐
Medium
medium.com › @j622amilah › javascript-basics-40-da5303fb9797
JavaScript Basics 40. Combine object values per key. | by Practicing DatScy | Medium
March 29, 2025 - const obj0 = {a: 1, b: 2, c: 2}; const obj1 = {a: 2, c: 5}; var out = combine_obj_values_per_key(obj0, obj1); console.log("out: ", out); function combine_obj_values_per_key(obj0, obj1) { var out2 = [Object.keys(obj0), Object.keys(obj1)]; out2 = out2.flat(Infinity); // console.log("out2: ", out2); var cnt = Counter(out2).filter((x) => x.at(1) > 1); // console.log("cnt: ", cnt); var obj2 = {}; var new_keyvalue = cnt.map((v,i) => { var key = v.at(0); obj2[key] = [obj0[key], obj1[key]]; return ""; }); // console.log("new_keyvalue: ", new_keyvalue); return {...obj0, ...obj1, ...obj2}; } function Counter(arr) { const arr_uq = [... new Set(arr)]; return arr_uq.map((v,i) => { const cnt = arr.map((v0,j) => { return (v0 === v) ?
Top answer
1 of 5
17

Another answer to show 1-liners for joining keys, or values, or both:


Join Keys: Object.keys(obj)

const obj = {a: '1', b: '2'};
console.log(Object.keys(obj).join(','));


Join Values: Object.values(obj)

const obj = {a: '1', b: '2'};
console.log(Object.values(obj).join(','));


Join Both: Object.entries(obj)

const obj = {a: '1', b: '2'};
console.log(Object.entries(obj).join(','));

Note: Object.entries(obj) was announced a standard by ecma in June 2017 (See link). Browser support: all except IE Desktop and Mobile Safari.

Update: Object.entries(obj) now supports in Mobile Safari Also

Ref: developer.mozilla.org

2 of 5
12

You can use Array#map method along with Array#join method. Where Array#filter method can be used for filtering non-empty and defined property values.

function obsKeysToString(o, k, sep) {
 // iterate over key array
 return k.map(function(key) {
    // get object property value 
    return o[key];
    // filter out non-empty and defined property
  }).filter(function(v) {
    return v;
    // join the property value array with the separator
  }).join(sep);
}

var keys = ['name', 'description']

var obj = {
  id: 1,
  name: 'Test',
  description: 'Lorem ipsum dolores',
  moreKeysHere: 'moreValues'
}

function obsKeysToString(o, k, sep) {
  return k.map(function(key) {
    return o[key];
  }).filter(function(v) {
    return v;
  }).join(sep);
}

console.log(obsKeysToString(obj, keys, '-'))


Same solution with ES6 arrow function

function obsKeysToString(o, k, sep) {
 return k.map(key => o[key]).filter(v => v).join(sep);
}

var keys = ['name', 'description']

var obj = {
  id: 1,
  name: 'Test',
  description: 'Lorem ipsum dolores',
  moreKeysHere: 'moreValues'
}

function obsKeysToString(o, k, sep) {
  return k.map(key => o[key]).filter(v => v).join(sep);
}
console.log(obsKeysToString(obj, keys, '-'))


Another solution using Array#reduce method.

function obsKeysToString(o, k, sep) {
  // iterate over key array
  return k.reduce(function(str, key) {
    // generate string based on each key
    return str + (o.hasOwnProperty(key) ? (str.length ? sep : '') + o[key] : '');
  }, '')
}

var keys = ['name', 'description']

var obj = {
  id: 1,
  name: 'Test',
  description: 'Lorem ipsum dolores',
  moreKeysHere: 'moreValues'
}

function obsKeysToString(o, k, sep) {
  return k.reduce(function(str, key) {
    return str + (o.hasOwnProperty(key) ? (str.length ? sep : '') + o[key] : '');
  }, '')
}

console.log(obsKeysToString(obj, keys, '-'))

🌐
30 Seconds of Code
30secondsofcode.org › home › javascript › object › merge objects
Merge two or more JavaScript objects - 30 seconds of code
March 20, 2024 - In order to do so, we can use ... keys. We can then use Array.prototype.reduce() to add each unique key to the object, using the provided function to combine the values of the two given objects....
🌐
Better Programming
betterprogramming.pub › combining-javascript-objects-e293bc4a48a6
3 Ways To Combine JavaScript Objects | by Corey Butler | Better Programming
March 5, 2021 - 3 Ways To Combine JavaScript Objects Using the assign method, loops, and the spread operator Objects are a powerful part of JavaScript. They are the inspiration for JSON (JavaScript Object Notation) …
🌐
W3Resource
w3resource.com › javascript › object-property-method › array-join.php
Array Object - JavaScript join() Method
var fruits = new Array("Orange", "Apple", "Banana", "Chery"); var fruitslist1=fruits.join(); var newParagraph = document.createElement("p"); var newText = document.createTextNode("Fruits List : " + fruitslist1 ); newParagraph.appendChild(newText); document.body.appendChild(newParagraph); var fruitslist2=fruits.join(', '); var newParagraph1 = document.createElement("p"); var newText1 = document.createTextNode("Fruits List : " + fruitslist2); newParagraph1.appendChild(newText1); document.body.appendChild(newParagraph1); var fruitslist3=fruits.join('-'); var newParagraph2 = document.createElement("p"); var newText2 = document.createTextNode("Fruits List : " + fruitslist3); newParagraph2.appendChild(newText2); document.body.appendChild(newParagraph2); ... JavaScript Core objects, methods, properties.