Simple:

var data = [{"name":"Marine Lines","location_id":3},{"name":"Ghatkopar","location_id":2}]
var result = data.map(function(val) {
  return val.location_id;
}).join(',');

console.log(result)

I assume you wanted a string, hence the .join(','), if you want an array simply remove that part.

Answer from Chrillewoodz on Stack Overflow
🌐
OneCompiler
onecompiler.com › javascript › 3xfqsme8y
convert a json array of objects to comma separated values - JavaScript - OneCompiler
//Object spread const post = { ...options, type: "new", } //array spread const users = [...adminUsers, ...normalUsers]
🌐
n8n
community.n8n.io › questions
Json to array comma - Questions - n8n Community
May 16, 2022 - Hello everyone. I trying to convert a json data to a string comma separated. Json is like this one: [ { "id": "625d757724acbe52634e6172", "idBoard": "625850ac4247c214ff3dc167", "name": "ANGELIS", "color": "yellow" }, { "id": "625d57da6bfa728b6684ed43", "idBoard": "625850ac4247c214ff3dc167", ...
🌐
Experts Exchange
experts-exchange.com › questions › 28652216 › How-to-get-convert-json-array-to-comma-separated-values.html
Solved: How to get convert json array to comma separated values | Experts Exchange
April 8, 2015 - What exception do you get and what JSONTokener are you using ? http://www.massapi.com/class/js/JSONTokener-1.html#Example6 And I believe this should work · String input ='[{"filter":"ID","filterValues":["050886","050885","050884","050883","050882"]}]'; JSONArray jsonarray = (JSONArray) new JSONTokener(input ).nextValue(); for (int i = 0; i < jsonarray.length(); i++) { JSONObject jsonobject = jsonarray.getJSONObject(i); String field= jsonobject.getString("filter"); String values= jsonobject.getJSONObject("filterValues"); }
Find elsewhere
🌐
Microsoft Power Platform Community
powerusers.microsoft.com › t5 › Building-Flows › JSON-received-as-a-comma-separated-string-need-help-in › td-p › 676482
https://powerusers.microsoft.com/t5/Building-Flows...
Quickly search for answers, join discussions, post questions, and work smarter in your business applications by joining the Microsoft Dynamics 365 Community.
🌐
Stack Overflow
stackoverflow.com › questions › 54230873 › transform-comma-separated-strings-to-json
javascript - Transform comma separated strings to JSON - Stack Overflow
11 jQuery: Convert string with comma separated values to specific JSON format · 0 how to convert json objects sepeted by comma into object · 2 Convert a JSON Object to Comma Sepearted values in javascript · 10 how to convert json values in comma separated string using javascript ·
🌐
Stack Overflow
stackoverflow.com › questions › 49098104 › convert-json-values-in-comma-separated-string-using-javascript
convert json values in comma separated string using javascript - Stack Overflow
March 4, 2018 - var x = '{"name":"Marine Lines","name":"jerry"}'; x = JSON.parse(x); var name = x.name; console.log(name); ... First of all, your object has the name key twice, which means only the latter will be saved.
🌐
W3Resource
w3resource.com › javascript-exercises › fundamental › javascript-fundamental-exercise-4.php
JavaScript fundamental (ES6 Syntax): Convert a comma-separated values string to a 2D array of objects - w3resource
July 3, 2025 - const CSV_to_JSON = (data, delimiter = ',') => { // Extract titles from the first row of the CSV data. const titles = data.slice(0, data.indexOf('\n')).split(delimiter); // Split the CSV data by newline characters, map each row to a JSON object with titles as keys. return data .slice(data.indexOf('\n') + 1) .split('\n') .map(v => { const values = v.split(delimiter); // Create a JSON object using titles and corresponding values. return titles.reduce((obj, title, index) => ((obj[title] = values[index]), obj), {}); }); }; // Test cases console.log(CSV_to_JSON('col1,col2\na,b\nc,d')); // [{'col1':
Top answer
1 of 2
4

This is an invalid notation - either JavaScript object or JSON. If you can fix your input or can make someone fix it, then it is definitely better to make your data source be valid.

However, sometimes we have to work with wrong data (external providers etc.), then you can make it a valid JSON array by adding a couple brackets in the beginning and the end:

var str = '{ "name":"a",  "surname":"b" }, {  "name":"c",  "surname":"d" }, {  "name":"e",  "surname":"f" }';
var arr = JSON.parse("[" + str + "]");
//console.log(arr);

for (var i = 0; i < arr.length; i++)
{
  console.log("Name #" + (i + 1) + ": " + arr[i].name);
  console.log("Surname #" + (i + 1) + ": " + arr[i].surname);
}

It can look a little bit hacky, but it is the best thing you can do when you have to work with such input.
It looks much better than trying to split an object by commas manually, at least for me.

2 of 2
0

I have one function to split your Array of Objects in many Arrays as you want, see the code :)

var BATCH_SIZE = 2;

var fullList = [{name:"a",surname:"e"},{name:"a",surname:"e"}
  , {name:"a",surname:"e"},{name:"a",surname:"e"}, {name:"a",surname:"e"}];

Batchify(fullList,BATCH_SIZE);

function Batchify(fullList,BATCH_SIZE){
    var batches = [];
    var currentIndex = 0;
    while (currentIndex < fullList.length) {
       var sliceStart = currentIndex;
       var sliceEnd = currentIndex + BATCH_SIZE;
       batches.push(fullList.slice(sliceStart, sliceEnd));
       currentIndex += BATCH_SIZE;
    }
    console.log(batches);
}

I have example of code in JSfiddle, I hope solve your problem! :)

🌐
GeeksforGeeks
geeksforgeeks.org › convert-comma-separated-string-to-array-using-javascript
JavaScript – Convert Comma Separated String To Array | GeeksforGeeks
November 26, 2024 - In this article, we will explore three different approaches to make a comma-separated string from a list of strings in Python. Make Comma-Separ ... Given a string, the task is to convert the given string to an array of objects using JavaScript. It is a common task, especially when working with JSON ...
🌐
ServiceNow Community
servicenow.com › community › developer-forum › convert-array-string-to-comma-separated-string › m-p › 2606171
Convert Array String to Comma Separated String - ServiceNow Community
July 6, 2023 - var tempString = ''; for(key in sortedArray) { tempString = tempString + JSON.stringify(sortedArray[key]); } ... How to Decrypt OpenSSL AES-256-CBC Secrets in ServiceNow via PowerShell in Developer forum 3 weeks ago · Convert and populate date of String type to the Date type field using field map script(transform map in Developer forum 4 weeks ago · Convert and populate date of String type to the Date type field using field map script(transform map in Developer forum 4 weeks ago