The format you're trying to create is not syntactically correct, you can't have key/value pairs in an array. However, you could use an object instead:

var obj = {};
["One", "TWO", "THREE"].forEach(function(v) {
  obj[v] = 'CNX';
});
console.log(obj);

Answer from Rory McCrossan on Stack Overflow
🌐
Syncopika
syncopika.github.io › basic-JSON-generator
Basic JSON Generator
Welcome to the basic JSON generator tool. Easily create simple JSON files with multiple key-value pairs. No need to worry about formatting – just add your data and download your JSON file. Try it now!
🌐
freeCodeCamp
forum.freecodecamp.org › curriculum help
How to make data in an array the keys of a JSON file? - Curriculum Help - The freeCodeCamp Forum
February 14, 2023 - I was processing some data and I have filtered the data to a point where I have stored the data which should be the keys of the JSON file I want to create into an array like this [ 'A', 'B', 'C', 'D', 'E' ] N…
Top answer
1 of 2
2

I would use the js map method (https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Array/map)

let output = this.responseStatus.dynaModel.map(item => item.map);
2 of 2
1

dynaModel is an array of objects so you can loop throuh it and pick map property (which is an object also) of every object in and put that object into output array.

let response = {
  "dynaModel": [
    {
      "map": {
        "UNIT/SUBUNIT": "EAS",
        "SUBUNIT/ISU/GEO": "Africa",
        "'APR-16'_REVENUEUSD-$": "$805,298",
        "'APR-16'_COSTUSD-$": "$701,026",
        "'APR-16'_GMINR-RSUSD-$": 12.95,
        "'Total'_REVENUEUSD-$": "$805,298",
        "'Total'_COSTUSD-$": "$701,026",
        "'Total'_GMINR-RSUSD-$": 12.95
      }
    },
    {
      "map": {
        "UNIT/SUBUNIT": "fgdfg",
        "SUBUNIT/ISU/GEO": "dfgdfg",
        "'APR-16'_REVENUEUSD-$": "$58,",
        "'APR-16'_COSTUSD-$": "$32,",
        "'APR-16'_GMINR-RSUSD-$": 43.98,
        "'Total'_REVENUEUSD-$": "$58,",
        "'Total'_COSTUSD-$": "$32,",
        "'Total'_GMINR-RSUSD-$": 43
      }
    }
  ]
}

let output = new Array();

for (let object of response.dynaModel) {
  output.push(object.map);
}

console.log(output); 

prints:

[ { 'UNIT/SUBUNIT': 'EAS',
'SUBUNIT/ISU/GEO': 'Africa',
'\'APR-16\'_REVENUEUSD-$': '$805,298',
'\'APR-16\'_COSTUSD-$': '$701,026',
'\'APR-16\'_GMINR-RSUSD-$': 12.95,
'\'Total\'_REVENUEUSD-$': '$805,298',
'\'Total\'_COSTUSD-$': '$701,026',
'\'Total\'_GMINR-RSUSD-$': 12.95 },
{ 'UNIT/SUBUNIT': 'fgdfg',
'SUBUNIT/ISU/GEO': 'dfgdfg',
'\'APR-16\'_REVENUEUSD-$': '$58,',
'\'APR-16\'_COSTUSD-$': '$32,',
'\'APR-16\'_GMINR-RSUSD-$': 43.98,
'\'Total\'_REVENUEUSD-$': '$58,',
'\'Total\'_COSTUSD-$': '$32,',
'\'Total\'_GMINR-RSUSD-$': 43 } ]
Find elsewhere
🌐
Data and Open Source
ftisiot.net › postgresqljson › howto-create-json-from-array-key-value-pairs-postgresql
How to create a JSON object from array of key/value pairs in PostgreSQL®? | Data and Open Source
PostgreSQL® offers two types of data types to handle JSON data, JSON and JSONB, you can use the function json_object (jsonb_object for JSONB) to create a JSON object from an array of key/value pairs.
🌐
TutorialsPoint
tutorialspoint.com › javascript-how-to-create-an-object-from-key-value-pairs
JavaScript: How to Create an Object from Key-Value Pairs
<!DOCTYPE html> <html> <head> <title>Object Using Key-value Pair</title> </head> <body> <h1 style="color: green;"> Welcome to Tutorials Point</h1> <script type="text/javascript"> let object={}; let keys = ["name", "tagLine", "Title"]; let values = ["Welcome To Tutorials Point", "Simply Learning", "Start your learning journey now."]; for (let i = 0; i < keys.length; i++) { object[keys[i]] = values[i]; } console.log(object); </script> </body> </html>
🌐
Micro Focus
microfocus.com › documentation › silk-performer › 195 › en › silkperformer-195-webhelp-en › GUID-6AFC32B4-6D73-4FBA-AD36-E42261E2D77E.html
JSON Object Structure - Micro Focus
A key-value pair consists of a key and a value, separated by a colon (:). The key is a string, which identifies the key-value pair. The value can be any of the following data types: { } //Empty JSON object { “StringProperty”: “StringValue”, “NumberProperty”: 10, “FloatProperty”: 20.13, “BooleanProperty”: true, “EmptyProperty”: null } { “NestedObjectProperty”: { “Name”: “Neste Object” }, “NestedArrayProperty”: [10,20,true,40] }
🌐
Kii Cloud
docs.kii.com › en › guides › cloudsdk › android › managing-data › json-document › set-key-value
Setting a Key-value Pair - Kii Documentation
The maximum size of a KiiObject is 65534 characters (the total size of key-value pairs in the JSON format, including some internal fields used by Kii Cloud). You can use any of the following data types for setting a value with the set() method.