Javascript has a built in JSON parse for strings, which I think is what you have:

var myObject = JSON.parse("my json string");

to use this with your example would be:

var jsonData = JSON.parse(myMessage);
for (var i = 0; i < jsonData.counters.length; i++) {
    var counter = jsonData.counters[i];
    console.log(counter.counter_name);
}

Here is a working example

EDIT: There is a mistake in your use of for loop (I missed this on my first read, credit to @Evert for the spot). using a for-in loop will set the var to be the property name of the current loop, not the actual data. See my updated loop above for correct usage

IMPORTANT: the JSON.parse method wont work in old old browsers - so if you plan to make your website available through some sort of time bending internet connection, this could be a problem! If you really are interested though, here is a support chart (which ticks all my boxes).

Answer from musefan on Stack Overflow
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array › from
Array.from() - JavaScript | MDN
The Array.from() static method creates a new, shallow-copied Array instance from an iterable or array-like object.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › JSON › parse
JSON.parse() - JavaScript | MDN
The JSON.parse() static method parses a JSON string, constructing the JavaScript value or object described by the string. An optional reviver function can be provided to perform a transformation on the resulting object before it is returned.
🌐
SitePoint
sitepoint.com › javascript
Parsing an array and making new arrays based on data in it - JavaScript - SitePoint Forums | Web Development & Design Community
October 19, 2018 - Hi all, I have an array rawData that would contain data like: rawData= [ “x: 1”, “y: 3”, “z: 9”, “x: 6”, “y: 7”, “z: 8”, “x: 1”, “y: 2”, “z: 5”] we are not sure how many categories would there be, like in this case we have three x, y and z. Having this array in mind, I want a different array for each category with its values like x = [1,6,1] y=[3,7,2] z=[9,8,5] I am quite new to java script, so I don’t really have many ideas how can I solve this issue.
🌐
MDN Web Docs
developer.mozilla.org › en-US › docs › Web › JavaScript › Reference › Global_Objects › Array
Array - JavaScript | MDN
Array elements are object properties in the same way that toString is a property (to be specific, however, toString() is a method). Nevertheless, trying to access an element of an array as follows throws a syntax error because the property name is not valid: ... JavaScript syntax requires properties beginning with a digit to be accessed using bracket notation instead of dot notation.
🌐
W3Schools
w3schools.com › js › js_json_parse.asp
JSON.parse()
... <p id="demo"></p> <script> ... using the JSON.parse() on a JSON derived from an array, the method will return a JavaScript array, instead of a JavaScript object....
🌐
Bobby Hadz
bobbyhadz.com › blog › javascript-parse-json-array
How to parse a JSON Array in JavaScript | bobbyhadz
Use the JSON.parse() method to parse a JSON array, e.g. JSON.parse(arr). The method parses a JSON string and returns its JavaScript value or object equivalent.
Find elsewhere
Top answer
1 of 3
2

Thought these two operation can be done together for clean writing you can do the following.

map to add the difference between the two property in a new property called d

using Math.abs to keep the difference positive.

let teams = [{"team":"Arsenal","f":"79","a":"36"},
{"team":"Liverpool","f":"67","a":"30"},
{"team":"Manchester_U","f":"87","a":"45"},
{"team":"Newcastle","f":"74","a":"52"},
{"team":"Leeds","f":"53","a":"37"},
{"team":"Chelsea","f":"66","a":"38"},
{"team":"West_Ham","f":"48","a":"57"},
{"team":"Aston_Villa","f":"46","a":"47"},
{"team":"Tottenham","f":"49","a":"53"},
{"team":"Blackburn","f":"55","a":"51"},
{"team":"Southampton","f":"46","a":"54"},
{"team":"Middlesbrough","f":"35","a":"47"},
{"team":"Fulham","f":"36","a":"44"},
{"team":"Charlton","f":"38","a":"49"},
{"team":"Everton","f":"45","a":"57"},
{"team":"Bolton","f":"44","a":"62"},
{"team":"Sunderland","f":"29","a":"51"},
{"team":"Ipswich","f":"41","a":"64"},
{"team":"Derby","f":"33","a":"63"},
{"team":"Leicester","f":"30","a":"64"}];

teams.map((t) => t['d'] = Math.abs(t.f - t.a))

console.log(teams);

To reduce to the team that has the lowest difference you can use the below code with reduce

    let teams = [{"team":"Arsenal","f":"79","a":"36"},
    {"team":"Liverpool","f":"67","a":"30"},
    {"team":"Manchester_U","f":"87","a":"45"},
    {"team":"Newcastle","f":"74","a":"52"},
    {"team":"Leeds","f":"53","a":"37"},
    {"team":"Chelsea","f":"66","a":"38"},
    {"team":"West_Ham","f":"48","a":"57"},
    {"team":"Aston_Villa","f":"46","a":"47"},
    {"team":"Tottenham","f":"49","a":"53"},
    {"team":"Blackburn","f":"55","a":"51"},
    {"team":"Southampton","f":"46","a":"54"},
    {"team":"Middlesbrough","f":"35","a":"47"},
    {"team":"Fulham","f":"36","a":"44"},
    {"team":"Charlton","f":"38","a":"49"},
    {"team":"Everton","f":"45","a":"57"},
    {"team":"Bolton","f":"44","a":"62"},
    {"team":"Sunderland","f":"29","a":"51"},
    {"team":"Ipswich","f":"41","a":"64"},
    {"team":"Derby","f":"33","a":"63"},
    {"team":"Leicester","f":"30","a":"64"}];
    teams.map((t) => t['d'] = Math.abs(t.f - t.a))
    
    // now finding the team with the lowsest
    
    let result = teams.reduce((teamA,teamB) => teamA.d > teamB.d? teamB: teamA );

    console.log(result);

2 of 3
1

Both using loop (e.g. for...of ) or array methods (e.g. map for the part 1 and filter for part 2) are valid approach.

I personally prefer loop because it is easier to read and debug and you can combine both steps into one loop. something like:

// use the first element as starter then update in the loop
let leastDiff = Math.abs(myArray[0].f - myArray[0].a);
let bestTeam = myArray[0].team;
for (let item of myArray) {
  item.diff = Math.abs(item.f - item.a);
  if (item.diff < leastDiff) {
    leastDiff = item.diff;
    bestTeam = item.team;
  }
}
console.log(`Team with least difference is ${bestTeam} with ${leastDiff} goal difference`);
🌐
DEV Community
dev.to › jules_k › array-map-parseint-in-javascript-3ig
Array.map & parseInt in JavaScript - DEV Community
August 18, 2020 - For '1' in base 0, parseInt evaluates 0 as falsey and the effect is the same as not passing a radix argument and it defaults to 10 so it is like writing it parseInt('1', 10) For '2' in base 1, it returns NaN, because radix must be an integer between 2 and 36. For '10' in base 2, it evaluates to 2. If you want to convert array string values to integer values you could do this:
🌐
EDUCBA
educba.com › home › software development › software development tutorials › javascript tutorial › json parse array
JSON Parse Array | How does JSON Parse Array Work in Javascript?
April 13, 2023 - First, the json is to read the user data from the web servers and displayed the data in the web page first is converted into the string format using JSON.stringify() and next is again converted string into arrays using JSON.parse() method.This ...
Address   Unit no. 202, Jay Antariksh Bldg, Makwana Road, Marol, Andheri (East),, 400059, Mumbai
🌐
ZetCode
zetcode.com › javascript › jsonparse
JavaScript JSON.parse - Parsing JSON Strings
Explore how to use JSON.parse in JavaScript to convert JSON strings into objects, with examples and explanations.
🌐
ReasonML Forums
reasonml.chat › t › how-to-parse-a-js-array-containing-multiple-types › 803
How to parse a JS Array containing multiple types - BuckleScript - ReasonML Forums
Lets say I have the following Variant type: type Fruit = | Apple(array(int)) | Banana(string) | Orange(array((string, int)) and want to parse JS code: [ "Apple", [1, 10, 20] ] [ "Banana", "taste nic…
🌐
Delft Stack
delftstack.com › home › howto › javascript › convert string to array javascript
How to Convert String Into Array in JavaScript | Delft Stack
February 2, 2024 - And, if the data is a JSON value derived from an array, JSON.parse() converts the data into a JavaScript array. We can use JSON.parse() to convert a string of numbers separated by commas into an array.
🌐
Educative
educative.io › answers › how-to-convert-a-string-into-an-array-in-javascript
How to convert a string into an array in JavaScript
In this shot, we will cover how to convert a string into an array in JavaScript. ... JSON.parse() will throw an exception if the string representation of the array is incorrect.
🌐
Mixu
book.mixu.net › node › ch5.html
5. Arrays, Objects, Functions and JSON - Mixu's Node book
For example, to check whether a particular string contains at least one of the tokens in an array, use some(): var types = ['text/html', 'text/css', 'text/javascript']; var string = 'text/javascript; encoding=utf-8'; if (types.some(function(value) { return string.indexOf(value) > -1; })) { console.log('The string contains one of the content types.'); }
🌐
TutorialsPoint
tutorialspoint.com › parsing-array-of-objects-inside-an-object-using-maps-or-foreach-using-javascript
Parsing array of objects inside an object using maps or forEach using JavaScript?
<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <title>Document</title> <style> body { font-family: "Segoe UI", Tahoma, Geneva, Verdana, sans-serif; } .result { font-size: 18px; font-weight: 500; color: rebeccapurple; } </style> </head> <body> <h1>Parse array of objects inside object</h1> <div class="result"></div> <button class="Btn">CLICK HERE</button> <h3>Click on the above button to parse the json object</h3> <script> let json = { storeData: [ { items: [ { itemID: 12, cost: { costNum: 100, }, }, { ite
🌐
GeeksforGeeks
geeksforgeeks.org › javascript › how-to-convert-string-of-objects-to-array-in-javascript
How to Convert String of Objects to Array in JavaScript ? - GeeksforGeeks
July 23, 2025 - This is a common scenario when dealing with JSON data received from a server or stored in a file. ... The most common and straightforward way to convert a string of objects to an array of objects is by using JSON.parse() method.