Parse JSON array and object in JavaScript? - javascript

I'm using Google analytics API to get a JSON message from the server. The message I receive is this one :
{
"reports": [
{
"columnHeader": {
"dimensions": [
"ga:landingPagePath"
],
"metricHeader": {
"metricHeaderEntries": [
{
"name": "ga:pageviews",
"type": "INTEGER"
},
{
"name": "ga:sessions",
"type": "INTEGER"
}
]
}
},
"data": {
"rows": [
{
"dimensions": [
"/-chandigarh/axis-bank-sarsini-branch_chandigarh_chg_850458.html"
],
"metrics": [
{
"values": [
"1",
"1"
]
}
]
},
{
"dimensions": [
"/267249-1.compliance-alex.xyz"
],
"metrics": [
{
"values": [
"29",
"10"
]
}
]
},
{
"dimensions": [
"/267249-1.compliance-don.xyz"
],
"metrics": [
{
"values": [
"27",
"9"
]
}
]
},
{
"dimensions": [
"/267249-1.compliance-fred.xyz"
],
"metrics": [
{
"values": [
"20",
"7"
]
}
]
},
{
"dimensions": [
"/abohar/axis-bank-the-fazilka-central-cooperative-bank-ltd-branch_abohar_frp_135.html"
],
"metrics": [
{
"values": [
"1",
"1"
]
}
]
},
{
"dimensions": [
"/about-us/career.htm"
],
"metrics": [
{
"values": [
"8",
"5"
]
}
]
},
{
"dimensions": [
"/about-us/company-profile.htm"
],
"metrics": [
{
"values": [
"34",
"14"
]
}
]
},
{
"dimensions": [
"/about-us/infrastructure.htm"
],
"metrics": [
{
"values": [
"3",
"1"
]
}
]
},
{
"dimensions": [
"/adilabad/gk-hospital-multispeciality-care_adilabad_adi_399806.html"
],
"metrics": [
{
"values": [
"2",
"1"
]
}
]
},
{
"dimensions": [
"/ahmedabad/akhani-jagdish-kumar_ahmedabad_ahd_1124498.html"
],
"metrics": [
{
"values": [
"7",
"3"
]
}
]
}
],
"totals": [
{
"values": [
"3420452",
"1333496"
]
}
],
"rowCount": 347614,
"minimums": [
{
"values": [
"0",
"1"
]
}
],
"maximums": [
{
"values": [
"56660",
"49274"
]
}
],
"isDataGolden": true
},
"nextPageToken": "1000"
}
]
}
I want to parse it and saved data in variable. How will I parse it. I tried many options but didn't get any data from JSON. Result is showing like undefined. I want to fetch the array data of dimensions and values like:
var a = "/-chandigarh/axis-bank-sarsini-branch_chandigarh_chg_850458.html";
var b = 1;
var c = 1;

Supposing your JSON input is stored in the json variable, you could just do:
var json = '{"reports":[{"columnHeader":{"dimensions":["ga:landingPagePath"],"metricHeader":{"metricHeaderEntries":[{"name":"ga:pageviews","type":"INTEGER"},{"name":"ga:sessions","type":"INTEGER"}]}},"data":{"rows":[{"dimensions":["/-chandigarh/axis-bank-sarsini-branch_chandigarh_chg_850458.html"],"metrics":[{"values":["1","1"]}]},{"dimensions":["/267249-1.compliance-alex.xyz"],"metrics":[{"values":["29","10"]}]},{"dimensions":["/267249-1.compliance-don.xyz"],"metrics":[{"values":["27","9"]}]},{"dimensions":["/267249-1.compliance-fred.xyz"],"metrics":[{"values":["20","7"]}]},{"dimensions":["/abohar/axis-bank-the-fazilka-central-cooperative-bank-ltd-branch_abohar_frp_135.html"],"metrics":[{"values":["1","1"]}]},{"dimensions":["/about-us/career.htm"],"metrics":[{"values":["8","5"]}]},{"dimensions":["/about-us/company-profile.htm"],"metrics":[{"values":["34","14"]}]},{"dimensions":["/about-us/infrastructure.htm"],"metrics":[{"values":["3","1"]}]},{"dimensions":["/adilabad/gk-hospital-multispeciality-care_adilabad_adi_399806.html"],"metrics":[{"values":["2","1"]}]},{"dimensions":["/ahmedabad/akhani-jagdish-kumar_ahmedabad_ahd_1124498.html"],"metrics":[{"values":["7","3"]}]}],"totals":[{"values":["3420452","1333496"]}],"rowCount":347614,"minimums":[{"values":["0","1"]}],"maximums":[{"values":["56660","49274"]}],"isDataGolden":true},"nextPageToken":"1000"}]}'
// Parse the JSON into the data variable
var data = JSON.parse(json);
data.reports.forEach(report => {
report.data.rows.forEach(row => {
// row.dimensions will contain your 'dimensions' array
console.log(row.dimensions);
row.metrics.forEach(metric => {
// metric.values will contain your 'values' array
console.log(metric.values);
});
});
});
You will just have to store these properties into your own variables.

Use json.parse
var json = '{"param1":1,"param2":2}',
obj = JSON.parse(json);
alert(obj.param1);
Most browsers e.g. Google support JSON.parse, moreover for those which don't support you can use json2 -> https://github.com/douglascrockford/JSON-js/blob/master/json2.js

Related

Convert JSON nested array to flat array

I have a JSON array which includes a nested array:
{
"data": [
{
"id": 659,
"created_at": "2023-01-13T06:35:08.000000Z",
"products": [
{
"name": "532",
"properties": [
{
"name": "color",
"value": "blue"
},
{
"name": "size",
"value": "1"
}
],
}
]
},
{
"id": 658,
"created_at": "2023-01-12T21:36:06.000000Z",
"products": [
{
"name": "532",
"properties": [
{
"name": "color",
"value": "khaki"
},
{
"name": "size",
"value": "2"
}
],
}
]
},
{
"id": 656,
"created_at": "2023-01-11T17:19:42.000000Z",
"products": [
{
"name": "2245/442",
"properties": [
{
"name": "color",
"value": "gray"
},
{
"name": "fabric",
"value": "fleece"
},
{
"name": "size",
"value": "2"
}
],
}
]
},
{
"id": 655,
"created_at": "2023-01-10T21:56:51.000000Z",
"products": [
{
"name": "298/426-2",
"properties": [
{
"name": "color",
"value": "blue"
},
{
"name": "fabric",
"value": "footer"
},
{
"name": "size",
"value": "4"
}
],
},
{
"name": "257/426",
"properties": [
{
"name": "color",
"value": "mint"
},
{
"name": "fabric",
"value": "footer"
},
{
"name": "size",
"value": "4"
}
],
}
]
},
],
}
I need to read it and write it to another array. All code I have so far:
var responce = UrlFetchApp.fetch(url, options);
var dataAll = JSON.parse(responce.getContentText());
var dataSet = dataAll.data;
var rows = [];
dataSet.forEach((e) => {
e.products.forEach((product) => {
product.properties.forEach((property) => {
rows.push([e.id, e.created_at, product.name, property.value]);
})
});
});
console.log(rows);
It writes data to an array in the form, that is, for each "product.value" value, it writes "id", "created_at", "name":
[ 659, '2023-01-13T06:35:08.000000Z', '532', 'blue' ],
[ 659, '2023-01-13T06:35:08.000000Z', '532', '1' ],
[ 658, '2023-01-12T21:36:06.000000Z', '532', 'khaki' ],
[ 658, '2023-01-12T21:36:06.000000Z', '532', '2' ],
[ 656, '2023-01-11T17:19:42.000000Z', '2245/442', 'gray' ],
[ 656, '2023-01-11T17:19:42.000000Z', '2245/442', 'fleece' ],
[ 656, '2023-01-11T17:19:42.000000Z', '2245/442', '2' ],
[ 655, '2023-01-10T21:56:51.000000Z', '298/426-2', 'blue' ],
[ 655, '2023-01-10T21:56:51.000000Z', '298/426-2', 'footer' ],
[ 655, '2023-01-10T21:56:51.000000Z', '298/426-2', '4' ],
[ 655, '2023-01-10T21:56:51.000000Z', '257/426', 'mint' ],
[ 655, '2023-01-10T21:56:51.000000Z', '257/426', 'footer' ],
[ 655, '2023-01-10T21:56:51.000000Z', '257/426', '4' ]
But I need to write like:
[ 659, '2023-01-13T06:35:08.000000Z', '532', 'blue', '1' ],
[ 658, '2023-01-12T21:36:06.000000Z', '532', 'khaki', '2' ],
[ 656, '2023-01-11T17:19:42.000000Z', '2245/442', 'gray', 'fleece', '2' ],
[ 655, '2023-01-10T21:56:51.000000Z', '298/426-2', 'blue', 'footer', '4' ],
[ 655, '2023-01-10T21:56:51.000000Z', '257/426', 'mint', 'footer', '4' ]
That is, I need to read the array "properties" and write the values "values" to a string (maybe I'm not expressing myself correctly).
I understand that I need to use the "map" function, but I don't understand how to use it yet ((
Thanks in advance for any advice
dataSet.forEach((e) => {
e.products.forEach((product) => {
rows.push([
e.id, e.created_at, product.name
].concat(product.properties.map(p => p.value)));
});
});
const rows = dataSet.map((item) => {
const newRows = [item.id, item.created_at];
item.products.forEach((product) => {
const properties = product.properties.map((property) => property.value);
newRows.push(product.name);
newRows.push(...properties);
});
return newRows;
});
console.log(rows);

javascript extract and convert into new array

I have the following array
[ {
"contactId": "a87d096gd5fuop",
"firstName": "John Doe",
"registrationTypes": {
"selectedOptions": [
{
}
],
"subTotal": 1620.003
},
"foo1": {
"selectedOptions": [
],
"subTotal": 0
},
"events": {
"selectedOptions": [
{
"id": "1",
"name": "T1",
"value": "4550006:3",
},
{
"id": "2",
"name": "T2",
"value": "4550005:3",
},
{
"id": "3",
"name": "T3",
"value": "4550003:3",
}
],
"subTotal": 135.003
},
"freeNetworkingFunctions": {
},
"total": 1755.0059999999999
},
{
"contactId": "a097f",
"firstName": "David",
"registrationTypes": {
"selectedOptions": [
{}
],
"subTotal": 899.998
},
"foo1": {
"selectedOptions": [
],
"subTotal": 0
},
"member": {
"selectedOptions": [
{
}
],
"subTotal": 228.8
},
"events": {
"selectedOptions": [
{
"id": "4",
"name": "T4",
"value": "4550002:2",
},
{
"id": "5",
"name": "T5",
"value": "4550001:2",
},
{
"id": "6",
"name": "T6",
"value": "4550003:2",
}
],
"subTotal": 135.003
},
"total": 1263.801
}
]
From the above array, I want to extract events, loop all the data and get only values. So my new array should be something like this:
[ {
"contactId": "a87d096gd5fuop",
"firstName": "John Doe",
"registrationTypes": {
"selectedOptions": [
{
}
],
"subTotal": 1620.003
},
"foo1": {
"selectedOptions": [
],
"subTotal": 0
},
"events": [
"4550006:3"
"4550005:3",
"4550003:3",
],
},
"freeNetworkingFunctions": {
},
"total": 1755.0059999999999
},
{
"contactId": "a097f",
"firstName": "David",
"registrationTypes": {
"selectedOptions": [
{}
],
"subTotal": 899.998
},
"foo1": {
"selectedOptions": [
],
"subTotal": 0
},
"member": {
"selectedOptions": [
{
}
],
"subTotal": 228.8
},
"events": [
"4550004:2"
"4550008:3",
"4550003:3",
],
"subTotal": 135.003
},
"total": 1263.801
}
]
So it should return the original array, however, events value data should be in one array.
var arr = [];
var r(var i=0;i<data.length;i++){
data.push(arr[i].value);
}
var newData = [...data, arr]
However, this doesn't work. Any help would be highly appreciated.
Use map twice - once on the dataset to iterate over the objects, and within that map to get an array of values from the selectedOptions.
const data=[{contactId:"a87d096gd5fuop",firstName:"John Doe",registrationTypes:{selectedOptions:[{}],subTotal:1620.003},foo1:{selectedOptions:[],subTotal:0},events:{selectedOptions:[{id:"1",name:"T1",value:"4550006:3"},{id:"2",name:"T2",value:"4550005:3"},{id:"3",name:"T3",value:"4550003:3"}],subTotal:135.003},freeNetworkingFunctions:{},total:1755.0059999999999},{contactId:"a097f",firstName:"David",registrationTypes:{selectedOptions:[{}],subTotal:899.998},foo1:{selectedOptions:[],subTotal:0},member:{selectedOptions:[{}],subTotal:228.8},events:{selectedOptions:[{id:"4",name:"T4",value:"4550002:2"},{id:"5",name:"T5",value:"4550001:2"},{id:"6",name:"T6",value:"4550003:2"}],subTotal:135.003},total:1263.801}];
const out = data.map(obj => {
// Destructure the selected options from the
// rest of each object
const { events: { selectedOptions }, ...rest } = obj;
// `map` over the options to just get an array of values
const events = selectedOptions.map(option => {
return option.value;
});
// Return a new object with the new events property
// combined with the other properties again
return { ...rest, events };
});
console.log(out);
Additional documentation
Destructuring assignment
Rest parameters
Spread syntax

how to remove empty document if it not matched in mongodb?

Could you please tell me how to remove empty documents if conditions not matched in mongoDB
I tried this query on shell
db.address.aggregate([
{ "$project": {
"applications": {
"$filter": {
"input": "$applications",
"as": "applications",
"cond": {
"$and": [
{ "$eq": ["$$applications.name", "DSB"] },
{ "$in": ["$$applications.code", ["122018"]] }
]
}
}
}
}}
])
my collection
[
{
"name": "test",
"applications": [
{
"code": [
"135001",
"122017"
],
"name": "HELLO"
}
]
},
{
"name": "test1",
"applications": [
{
"name": "HELLO",
"code": [
"135001",
"122017"
]
}
]
},
{
"name": "test2",
"applications": [
{
"code": [
"135001",
"122017"
],
"name": "HELLO"
}
]
},
{
"name": "test3",
"applications": [
{
"code": [
"135001",
"122017"
],
"name": "HELLO"
}
]
},
{
"name": "test4",
"applications": [
{
"code": [
"135001",
"122017"
],
"name": "HELLO"
}
]
},
{
"name": "test5",
"applications": [
{
"code": [
"135001",
"122017"
],
"name": "HELLO"
}
]
},
{
"name": "tes3",
"applications": [
{
"code": [
],
"name": "HELLO"
}
]
},
{
"name": "test22",
"applications": [
{
"code": [
"135001",
"122017"
],
"name": "DSB"
}
]
},
{
"name": "test89",
"applications": [
{
"code": [
"135001",
"122017"
],
"name": "DSB"
},
{
"code": [
"135001",
"122017"
],
"name": "HELLO"
}
]
},
{
"name": "test89",
"applications": [
{
"code": [
"135001",
"122018"
],
"name": "DSB"
},
{
"code": [
"135001",
"122017"
],
"name": "HELLO"
}
]
}
]
expected output
[
{
"name": "test89",
"applications": [
{
"code": [
"135001",
"122018"
],
"name": "DSB"
}
]
}
]
getting out put
{ "_id" : ObjectId("5d4143269d7b3f8883605a1e"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a1f"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a20"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a21"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a22"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a23"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a24"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a25"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a26"), "applications" : [ ] }
{ "_id" : ObjectId("5d4143269d7b3f8883605a27"), "applications" : [ ] }
Please suggest why I am not getting expected output ??
I want to filter my collection which have application name ‘DSB’ and have code 122018
See my expected output which have only one document which fulfil my condition have name DSB and code '122018'.
You need to use unwind and there is position issue in your $in condition
db.address.aggregate([
{
"$project": {
"applications": {
"$filter": {
"input": "$applications",
"as": "applications",
"cond": {
"$and": [
{ "$in": ['122018',"$$applications.code"] },
{ "$eq": ["$$applications.name", "DSB"] },
]
}
}
},
name:true
}
},
{ $unwind: { path: "$applications", preserveNullAndEmptyArrays: false } }
])

Add Object to Specific json PHP array

I have been looking for a while how to add this two objects to inside DATA of my json call.
i have try this
$signer = array(
'signatures' => array('some data'),
'pubkeys' => array('some data'),
);
array_push($result, $signer);
and the output is this. allways put thath two value in the begining of json squeleton. but i need put thath two values inside DATA SECTION
{
"0": {
"signatures": [
"some data"
],
"pubkeys": [
"some data"
]
},
"data": {
"tx": {
"block_height": -1,
"block_index": -1,
"hash": "69da371cacae35ae1c8426f09e51a028d820480551fa3c0821e6e1615883307e",
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"total": 20740200,
"fees": 13700,
"size": 119,
"preference": "high",
"relayed_by": "108.175.3.18",
"received": "2018-11-26T12:24:41.152398845Z",
"ver": 1,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 2,
"confirmations": 0,
"inputs": [
{
"prev_hash": "37120cd926d45499cc334e6915d3421ec244189f99575a38a3f7d63aa04c821e",
"output_index": 1,
"output_value": 20753900,
"sequence": 4294967295,
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"script_type": "pay-to-pubkey-hash",
"age": 976367
}
],
"outputs": [
{
"value": 20703900,
"script": "76a914257c9d647a3d522e1eaeb61df272fb3918f375b288ac",
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"script_type": "pay-to-pubkey-hash"
},
{
"value": 36300,
"script": "76a914257c9d647a3d522e1eaeb61df272fb3918f375b288ac",
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"script_type": "pay-to-pubkey-hash"
}
]
},
"tosign": [
"966c044f9c21f94f9708914540053015646bb216918ec31ffc874ab8785a222b"
]
}
}
the call should be seen as follows. signatures and pubkey should add inside DATA. the structure would look like this.
data
    tx
    tosign
    signatures
    pubkey
{ so this is the code with (signatures and pubkeys values)
"data": {
"tx": {
"block_height": -1,
"block_index": -1,
"hash": "69da371cacae35ae1c8426f09e51a028d820480551fa3c0821e6e1615883307e",
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"total": 20740200,
"fees": 13700,
"size": 119,
"preference": "high",
"relayed_by": "208.135.6.59",
"received": "2018-11-26T11:47:58.079469294Z",
"ver": 1,
"double_spend": false,
"vin_sz": 1,
"vout_sz": 2,
"confirmations": 0,
"inputs": [
{
"prev_hash": "37120cd926d45499cc334e6915d3421ec244189f99575a38a3f7d63aa04c821e",
"output_index": 1,
"output_value": 20753900,
"sequence": 4294967295,
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"script_type": "pay-to-pubkey-hash",
"age": 976367
}
],
"outputs": [
{
"value": 20703900,
"script": "76a914257c9d647a3d522e1eaeb61df272fb3918f375b288ac",
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"script_type": "pay-to-pubkey-hash"
},
{
"value": 36300,
"script": "76a914257c9d647a3d522e1eaeb61df272fb3918f375b288ac",
"addresses": [
"Xe747jtZwNWh8ZadnYKfYKZbzwDMA9zTJ1"
],
"script_type": "pay-to-pubkey-hash"
}
]
},
"tosign": [
"966c044f9c21f94f9708914540053015646bb216918ec31ffc874ab8785a222b"
],
"signatures": [
"sadasd"
],
"pubkeys": [
"0327d5d59731a19b0d4b00ffc50582572a4c3f6ad6887cf4af6b21b39fbe3ff5a4"
]
}
}

Comparing two array of objects in javascript

This is my static values which is having id with names:
var staticValues = [
{ "id": "1", "name": "PEKKA" },
{ "id": "2", "name": "Golem" },
{ "id": "3", "name": "Vigilane" },
{ "id": "4", "name": "SpiderMan" },
{ "id": "5", "name": "Archer" },
{ "id": "6", "name": "SuperMan" }
]
This is is my returned value from my method:
var myReturnedValues = [
[ [ "2", "4" ] ],
[ [ "5", "5" ] ],
[ [ "1", "3" ] ],
[ [ "4", "3" ] ]
]
My output needs to be like this:
var myReturnedValues = [
[ [ "Golem", "SpiderMan" ] ],
[ [ "Archer", "Archer" ] ],
[ [ "PEKKA", "Vigilante" ] ],
[ [ "SpiderMan", "Vigilante" ] ]
]
What am trying to do here is I have to compare staticValues and myReturnedValues and return names with respect to their ids instead of returning only ids alone. I tried some more ways with underscore.js but failed. Can someone give me idea about that?
This is how my method looks like:
var staticValues = [ /* here I have the whole static data */ ];
$scope.getCategories = function() {
var myReturnedValues = mainSteps.map(x => [x.steps.map(y => y.category)]);
return myReturnedValues;
}
Code After edited ,
$scope.getCategories =function(){
var myReturnedValues =mainSteps.map(x => [x.steps.map(y => y.category+"\n"+"\n"+"\n")]);
//return myReturnedValues;
console.log('meeee before',angular.toJson(myReturnedValues));
newval = {};
$.each(staticValues ,function(i,v) {
console.log('meeee staticCategories',angular.toJson(staticValues ));
newval[v.id] = v.name;
});
$.each(myReturnedValues,function(i,v){
$.each(v[0],function(x,t){
myReturnedValues[i][0][x] = newval[t];
});
});
console.log('meeee after',angular.toJson(myReturnedValues));
return myReturnedValues;
}
Start by converting staticValues to a key => value object:
names = {}
staticValues.forEach(obj => names[obj.id] = obj.name);
Then iterate myReturedValues and replace ids with names as you go:
var staticValues = [
{ "id": "1", "name": "PEKKA" },
{ "id": "2", "name": "Golem" },
{ "id": "3", "name": "Vigilane" },
{ "id": "4", "name": "SpiderMan" },
{ "id": "5", "name": "Archer" },
{ "id": "6", "name": "SuperMan" }
]
var myReturnedValues = [
[ [ "2", "4" ] ],
[ [ "5", "5" ] ],
[ [ "1", "3" ] ],
[ [ "4", "3" ] ]
]
names = {}
staticValues.forEach(x => names[x.id] = x.name)
res = myReturnedValues.map(sub =>
[sub[0].map(id => names[id])]
)
console.log(res)
Try the following loops:
newval = {};
$.each(staticValues,function(i,v) {
newval[v.id] = v.name;
});
var myReturedValues = [
[ [ "2", "4" ] ],
[ [ "5", "5" ] ],
[ [ "1", "3" ] ],
[ [ "4", "3" ] ]
];
$.each(myReturedValues,function(i,v){
$.each(v[0],function(x,t){
myReturedValues[i][0][x] = newval[t];
});
});
demo: https://jsfiddle.net/cgk478g8/
With underscore you can try like this:
var staticValues = [
{ "id": "1", "name": "PEKKA" },
{ "id": "2", "name": "Golem" },
{ "id": "3", "name": "Vigilane" },
{ "id": "4", "name": "SpiderMan" },
{ "id": "5", "name": "Archer" },
{ "id": "6", "name": "SuperMan" }
];
var myReturedValues = [
[ [ "2", "4" ] ],
[ [ "5", "5" ] ],
[ [ "1", "3" ] ],
[ [ "4", "3" ] ]
];
var data = _.chain(myReturedValues).map(function(d) {
//map the myReturedValues
return d[0].map(function(id) {
//use underscore to search in the staticValues and return name
return _.find(staticValues, function(svalue) {
return svalue.id == id
}).name
});
}).value();
console.log(data)
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.8.3/underscore-min.js"></script>

Categories