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
let arrayName = [value1, value2,..etc]; // or let arrayName = new Array("value1","value2",..etc);
Discussions

Get comma separated string from array
Is it correct to assume you made a typo and what you want is one string instead of several comma-separated strings? ... why do you want to convert a JSON array (with is supported by the JSON format) to a comma separated string? I can't think of a good reason to do it. More on stackoverflow.com
🌐 stackoverflow.com
May 24, 2017
How do I convert an array to a string with commas in JavaScript
...you get a better, more thorough explanation here: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/join More on reddit.com
🌐 r/JavaScriptTips
1
4
April 13, 2023
How to get convert json array to comma separated values
Find answers to How to get convert json array to comma separated values from the expert community at Experts Exchange More on experts-exchange.com
🌐 experts-exchange.com
April 8, 2015
javascript - JSON Object into Comma Separated String
I have problem with converting JSON Object into string with comma separated, Here's my code: $.ajax({ url:' ', method:'get', success: More on stackoverflow.com
🌐 stackoverflow.com
🌐
Reddit
reddit.com › r/javascripttips › how do i convert an array to a string with commas in javascript
r/JavaScriptTips on Reddit: How do I convert an array to a string with commas in JavaScript
April 13, 2023 -

In JavaScript, you can convert an array to a string with commas using the join()
method.

The join() method returns a string that concatenates all the elements of an array, separated by the specified separator, which in this case is a comma.

Here is an example:

const array = ['apple', 'banana', 'orange'];
const string = array.join(', ');
console.log(string); 

// output: "apple, banana, orange"

In this example, we first define an array of three fruits. Then we use the join()
method with a comma and a space as the separator to create a string that lists all the fruits with a comma and a space between each one.

You can replace the comma and space separator with any other separator you like, such as a hyphen, a semicolon, or a newline character.

It's important to note that the join() method only works on arrays, and it will throw an error if you try to use it on any other type of object.

Click here to learn more ways to Convert Array to String with Commas in JS

🌐
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
🌐
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", ...
🌐
W3Schools
w3schools.com › jsref › jsref_join.asp
JavaScript Array join() Method
The join() method returns an array as a string. The join() method does not change the original array. Any separator can be specified. The default is comma (,).
🌐
GeeksforGeeks
geeksforgeeks.org › create-a-comma-separated-list-from-an-array-in-javascript
Create a Comma Separated List from an Array in JavaScript | GeeksforGeeks
December 28, 2024 - The code uses map(String) to convert each element of the array arr into a string, and then join(',') joins these string elements with commas. The result is a comma-separated string "1,2,3,4,5", which is logged to the console.
🌐
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 - Hi, I suspect your issue is that your array is an array of objects, and so may need to iterate through the sorted array stringifying each element\object and concatenating these individually to your output string. ... var tempString = ''; for(key in sortedArray) { tempString = tempString + JSON.stringify(sortedArray[key]); }
🌐
MP4Moviez
pakainfo.com › home › javascript › jquery split string to array – how to split string to array by comma using jquery?
Jquery Split String To Array - How To Split String To Array By Comma Using Jquery? - Pakainfo
jquery split string to array : Use the split() Method splits a string into an array of substrings, and returns the new array. It splits a String object into