Unknown regularizer: L2 in tensorflowjs - javascript

I have trained a model in python using model
reg = 0.000001
model = Sequential()
model.add(Dense(24, activation='tanh', name='input_dense', input_shape=input_shape))
model.add(GRU(24, activation='tanh', recurrent_activation='sigmoid', return_sequences=True, kernel_regularizer=regularizers.l2(reg), recurrent_regularizer=regularizers.l2(reg), reset_after=False))
model.add(Flatten())
model.add(Dense(2, activation='softmax'))
But when I converted this model using "tensorflowjs_converter --input_format keras" and loaded in browser getting error
Unhandled Rejection (Error): Unknown regularizer: L2. This may be due
to one of the following reasons:
The regularizer is defined in Python, in which case it needs to be ported to TensorFlow.js or your JavaScript code.
The custom regularizer is defined in JavaScript, but is not registered properly with tf.serialization.registerClass().
The model.json file content is
{
"format": "layers-model",
"generatedBy": "keras v2.4.0",
"convertedBy": "TensorFlow.js Converter v2.3.0",
"modelTopology": {
"keras_version": "2.4.0",
"backend": "tensorflow",
"model_config": {
"class_name": "Sequential",
"config": {
"name": "sequential",
"layers": [
{
"class_name": "InputLayer",
"config": {
"batch_input_shape": [null, 22, 13],
"dtype": "float32",
"sparse": false,
"ragged": false,
"name": "input_dense_input"
}
},
{
"class_name": "Dense",
"config": {
"name": "input_dense",
"trainable": true,
"batch_input_shape": [null, 22, 13],
"dtype": "float32",
"units": 24,
"activation": "tanh",
"use_bias": true,
"kernel_initializer": {
"class_name": "GlorotUniform",
"config": { "seed": null }
},
"bias_initializer": { "class_name": "Zeros", "config": {} },
"kernel_regularizer": null,
"bias_regularizer": null,
"activity_regularizer": null,
"kernel_constraint": null,
"bias_constraint": null
}
},
{
"class_name": "GRU",
"config": {
"name": "gru",
"trainable": true,
"dtype": "float32",
"return_sequences": true,
"return_state": false,
"go_backwards": false,
"stateful": false,
"unroll": false,
"time_major": false,
"units": 24,
"activation": "tanh",
"recurrent_activation": "sigmoid",
"use_bias": true,
"kernel_initializer": {
"class_name": "GlorotUniform",
"config": { "seed": null }
},
"recurrent_initializer": {
"class_name": "Orthogonal",
"config": { "gain": 1.0, "seed": null }
},
"bias_initializer": { "class_name": "Zeros", "config": {} },
"kernel_regularizer": {
"class_name": "L2",
"config": { "l2": 9.999999974752427e-7 }
},
"recurrent_regularizer": {
"class_name": "L2",
"config": { "l2": 9.999999974752427e-7 }
},
"bias_regularizer": null,
"activity_regularizer": null,
"kernel_constraint": null,
"recurrent_constraint": null,
"bias_constraint": null,
"dropout": 0.0,
"recurrent_dropout": 0.0,
"implementation": 2,
"reset_after": false
}
},
{
"class_name": "Flatten",
"config": {
"name": "flatten",
"trainable": true,
"dtype": "float32",
"data_format": "channels_last"
}
},
{
"class_name": "Dense",
"config": {
"name": "dense",
"trainable": true,
"dtype": "float32",
"units": 2,
"activation": "softmax",
"use_bias": true,
"kernel_initializer": {
"class_name": "GlorotUniform",
"config": { "seed": null }
},
"bias_initializer": { "class_name": "Zeros", "config": {} },
"kernel_regularizer": null,
"bias_regularizer": null,
"activity_regularizer": null,
"kernel_constraint": null,
"bias_constraint": null
}
}
]
}
},
"training_config": {
"loss": "categorical_crossentropy",
"metrics": ["accuracy"],
"weighted_metrics": null,
"loss_weights": null,
"optimizer_config": {
"class_name": "Nadam",
"config": {
"name": "Nadam",
"learning_rate": 0.0020000000949949026,
"decay": 0.004000000189989805,
"beta_1": 0.8999999761581421,
"beta_2": 0.9990000128746033,
"epsilon": 1e-7
}
}
}
},
"weightsManifest": [
{
"paths": ["group1-shard1of1.bin"],
"weights": [
{ "name": "dense/kernel", "shape": [528, 2], "dtype": "float32" },
{ "name": "dense/bias", "shape": [2], "dtype": "float32" },
{ "name": "gru/gru_cell/kernel", "shape": [24, 72], "dtype": "float32" },
{
"name": "gru/gru_cell/recurrent_kernel",
"shape": [24, 72],
"dtype": "float32"
},
{ "name": "gru/gru_cell/bias", "shape": [72], "dtype": "float32" },
{ "name": "input_dense/kernel", "shape": [13, 24], "dtype": "float32" },
{ "name": "input_dense/bias", "shape": [24], "dtype": "float32" }
]
}
]
}

Option 1
There are no classes L1 and L2; they are just interfaces(more here)
There is a class L1L2 which will take the config and return the right regularizer. You can manually replace all occurences of L2 to L1L2.
Option 2
Register a class L2
class L2 {
static className = 'L2';
constructor(config) {
return tf.regularizers.l1l2(config)
}
}
tf.serialization.registerClass(L2);
// now load the model

Related

How to select some properties from a json result

I am trying to build a simple react app which lists my philips hue bulb name and state(on or off). I have API call which results in the following json. Not sure how to pull bulb name and state.on status.
Here is my json result which gets the list of bulbs connected to my hue bridge. I get this result when i fetch via a the philips hue API.
{
"1": {
"state": {
"on": false,
"bri": 254,
"hue": 50116,
"sat": 248,
"effect": "none",
"xy": [
0.2444,
0.0969
],
"ct": 500,
"alert": "select",
"colormode": "xy",
"mode": "homeautomation",
"reachable": true
},
"swupdate": {
"state": "noupdates",
"lastinstall": "2021-08-19T18:10:44"
},
"type": "Extended color light",
"name": "TV 2",
"modelid": "LCT016",
"manufacturername": "Signify Netherlands B.V.",
"productname": "Hue color lamp",
"capabilities": {
"certified": true,
"control": {
"mindimlevel": 1000,
"maxlumen": 800,
"colorgamuttype": "C",
"colorgamut": [
[
0.6915,
0.3083
],
[
0.1700,
0.7000
],
[
0.1532,
0.0475
]
],
"ct": {
"min": 153,
"max": 500
}
},
"streaming": {
"renderer": true,
"proxy": true
}
},
"config": {
"archetype": "sultanbulb",
"function": "mixed",
"direction": "omnidirectional",
"startup": {
"mode": "safety",
"configured": true
}
},
"uniqueid": "00:17:88:01:03:db:75:df-0b",
"swversion": "1.88.1",
"swconfigid": "47ACF9B2",
"productid": "Philips-LCT016-1-A19ECLv5"
},
"2": {
"state": {
"on": false,
"bri": 254,
"hue": 8417,
"sat": 140,
"effect": "none",
"xy": [
0.4573,
0.4100
],
"ct": 366,
"alert": "select",
"colormode": "ct",
"mode": "homeautomation",
"reachable": true
},
"swupdate": {
"state": "noupdates",
"lastinstall": "2021-08-19T18:10:39"
},
"type": "Extended color light",
"name": "Study",
"modelid": "LCT016",
"manufacturername": "Signify Netherlands B.V.",
"productname": "Hue color lamp",
"capabilities": {
"certified": true,
"control": {
"mindimlevel": 1000,
"maxlumen": 800,
"colorgamuttype": "C",
"colorgamut": [
[
0.6915,
0.3083
],
[
0.1700,
0.7000
],
[
0.1532,
0.0475
]
],
"ct": {
"min": 153,
"max": 500
}
},
"streaming": {
"renderer": true,
"proxy": true
}
},
"config": {
"archetype": "sultanbulb",
"function": "mixed",
"direction": "omnidirectional",
"startup": {
"mode": "safety",
"configured": true
}
},
"uniqueid": "00:17:88:01:03:94:fa:07-0b",
"swversion": "1.88.1",
"swconfigid": "47ACF9B2",
"productid": "Philips-LCT016-1-A19ECLv5"
}
}
You can map them into an array using map(). Since map only works on arrays, and your data is an object, you can use Object.values to return an array of the object's values and use map on that, like this:
const data={1:{state:{on:!1,bri:254,hue:50116,sat:248,effect:"none",xy:[.2444,.0969],ct:500,alert:"select",colormode:"xy",mode:"homeautomation",reachable:!0},swupdate:{state:"noupdates",lastinstall:"2021-08-19T18:10:44"},type:"Extended color light",name:"TV 2",modelid:"LCT016",manufacturername:"Signify Netherlands B.V.",productname:"Hue color lamp",capabilities:{certified:!0,control:{mindimlevel:1e3,maxlumen:800,colorgamuttype:"C",colorgamut:[[.6915,.3083],[.17,.7],[.1532,.0475]],ct:{min:153,max:500}},streaming:{renderer:!0,proxy:!0}},config:{archetype:"sultanbulb",function:"mixed",direction:"omnidirectional",startup:{mode:"safety",configured:!0}},uniqueid:"00:17:88:01:03:db:75:df-0b",swversion:"1.88.1",swconfigid:"47ACF9B2",productid:"Philips-LCT016-1-A19ECLv5"},2:{state:{on:!1,bri:254,hue:8417,sat:140,effect:"none",xy:[.4573,.41],ct:366,alert:"select",colormode:"ct",mode:"homeautomation",reachable:!0},swupdate:{state:"noupdates",lastinstall:"2021-08-19T18:10:39"},type:"Extended color light",name:"Study",modelid:"LCT016",manufacturername:"Signify Netherlands B.V.",productname:"Hue color lamp",capabilities:{certified:!0,control:{mindimlevel:1e3,maxlumen:800,colorgamuttype:"C",colorgamut:[[.6915,.3083],[.17,.7],[.1532,.0475]],ct:{min:153,max:500}},streaming:{renderer:!0,proxy:!0}},config:{archetype:"sultanbulb",function:"mixed",direction:"omnidirectional",startup:{mode:"safety",configured:!0}},uniqueid:"00:17:88:01:03:94:fa:07-0b",swversion:"1.88.1",swconfigid:"47ACF9B2",productid:"Philips-LCT016-1-A19ECLv5"}};
let bulbs = Object.values(data).map(
m=>{return {name: m.name, state: m.state.on}}
);
console.log(bulbs);

Create new Array of object based on the Property Value

I want to create a new Array of objects based on Interface Value.
Like we need to group objects with the same Interface value. The new array would be like two new Objects with the same interface value. So here in the new generated array of objects, there would be two objects. Such as GE5 and GE6.I have a limitation to use only ES5.
There should be a looping logic
Logic
Loop through the data array. Which is the input.
Loop through cloudServices nodes in each node of the data and find the distict value.
Loop through this distinct values and and generate a group of each distict value using Array.filter.
Aggregate all the remainig values from each node in data array except the cloudServices node.
Generate a final object with this remaining values and the above generated group.
ES5 implementation
var data = [{ "id": 14042, "created": "2020-03-18T10:11:40.000Z", "enterpriseId": 437, "siteId": 6302, "activationKey": "PMZP-NGRU-HE64-SA5M", "activationKeyExpires": "2021-08-04T16:21:33.000Z", "activationState": "ACTIVATED", "activationTime": "2020-03-18T17:05:27.000Z", "softwareVersion": "4.3.0", "buildNumber": "R430-20210720-GA-64951-67694-6911a00421", "factorySoftwareVersion": "3.3.0", "factoryBuildNumber": "R330-MTHD-20190328-GA", "softwareUpdated": "2021-09-24T11:21:49.000Z", "selfMacAddress": "50:9a:4c:e4:1e:c0", "deviceId": "93AB7D33-87B7-42AA-BC0B-7D8255E069AD", "logicalId": "d25a6121-bf16-4512-b490-2dc5c45e11b8", "serialNumber": "F0TFXC2", "modelNumber": "edge610", "deviceFamily": "EDGE6X0", "name": "SDALM-BAYNARD-LAB-4", "dnsName": null, "description": "Dual Internet Site in Baynard", "alertsEnabled": 1, "operatorAlertsEnabled": 1, "edgeState": "CONNECTED", "edgeStateTime": "2021-09-24T11:23:00.000Z", "isLive": 0, "systemUpSince": "2021-09-24T11:20:55.000Z", "serviceUpSince": "2021-09-24T11:31:06.000Z", "lastContact": "2021-10-04T14:06:47.000Z", "serviceState": "IN_SERVICE", "endpointPkiMode": "CERTIFICATE_REQUIRED", "haState": "UNCONFIGURED", "haPreviousState": "UNCONFIGURED", "haLastContact": "0000-00-00 00:00:00", "haSerialNumber": null, "bastionState": "UNCONFIGURED", "modified": "2021-10-04T14:06:47.000Z", "customInfo": "", "isHub": false, "cloudServices": [{ "state": "UP", "timestamp": "2021-10-04T14:01:50.638Z", "link": "00000005-bf16-4512-b490-2dc5c45e11b8", "local_interface_ip": "172.16.2.1", "local_public_ip": "217.38.39.43", "nvs_ip": "165.225.16.236", "pathId": "211262ED9DE488A22CFEBBA9809092B32B937912", "segmentId": 0, "segmentLogicalId": "cd948075-e95f-4c7c-beb2-0fcde7e17c62", "l7_check": "UP", "l7_check_rtt": { "max": 11, "avg": 7, "min": 5 }, "site": { "id": 60282, "logicalId": "717f67c5-7426-4689-a74c-b58c93d4c3b1", "data": { "customSourceIp": "", "linkInternalLogicalId": "00000005-bf16-4512-b490-2dc5c45e11b8", "primaryAddressing": { "internalRouterIp": "172.22.60.145", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.146", "internalZenMask": "255.255.255.255" }, "secondaryAddressing": { "internalRouterIp": "172.22.60.149", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.150", "internalZenMask": "255.255.255.255" }, "useCustomSourceIp": false } }, "provider": { "name": "L7HC-LON3-MAN1-GRE", "id": 549697, "logicalId": "d5a058dc-6202-494c-b65d-6a8c273ed1c4", "data": { "primaryServer": "165.225.16.236", "secondaryServer": "165.225.196.39", "automateDeployment": false, "enableTunnels": true, "sharedIkeAuth": false, "maxTunnelsPerIkeIdentity": 128, "l7HealthCheck": { "enabled": true, "probeIntervalSec": 5, "numOfRetries": 3, "rttThresholdMs": 3000, "cloud": "zscloud.net" }, "provider": "zscalerWebSecurityService" } }, "segmentName": "Global Segment", "interface": "GE5" }, { "state": "STANDBY", "timestamp": "2021-10-04T14:01:50.638Z", "link": "00000005-bf16-4512-b490-2dc5c45e11b8", "local_interface_ip": "172.16.2.1", "local_public_ip": "217.38.39.43", "nvs_ip": "165.225.196.39", "pathId": "26434D16946CFD147D5DDFA50647F48A0066AB31", "segmentId": 0, "segmentLogicalId": "cd948075-e95f-4c7c-beb2-0fcde7e17c62", "l7_check": "UP", "l7_check_rtt": { "max": 10, "avg": 6, "min": 5 }, "site": { "id": 60282, "logicalId": "717f67c5-7426-4689-a74c-b58c93d4c3b1", "data": { "customSourceIp": "", "linkInternalLogicalId": "00000005-bf16-4512-b490-2dc5c45e11b8", "primaryAddressing": { "internalRouterIp": "172.22.60.145", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.146", "internalZenMask": "255.255.255.255" }, "secondaryAddressing": { "internalRouterIp": "172.22.60.149", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.150", "internalZenMask": "255.255.255.255" }, "useCustomSourceIp": false } }, "provider": { "name": "L7HC-LON3-MAN1-GRE", "id": 549697, "logicalId": "d5a058dc-6202-494c-b65d-6a8c273ed1c4", "data": { "primaryServer": "165.225.16.236", "secondaryServer": "165.225.196.39", "automateDeployment": false, "enableTunnels": true, "sharedIkeAuth": false, "maxTunnelsPerIkeIdentity": 128, "l7HealthCheck": { "enabled": true, "probeIntervalSec": 5, "numOfRetries": 3, "rttThresholdMs": 3000, "cloud": "zscloud.net" }, "provider": "zscalerWebSecurityService" } }, "segmentName": "Global Segment", "interface": "GE5" }, { "state": "STANDBY", "timestamp": "2021-10-04T14:01:50.638Z", "link": "00000006-bf16-4512-b490-2dc5c45e11b8", "local_interface_ip": "172.16.1.1", "local_public_ip": "217.38.39.41", "nvs_ip": "165.225.196.39", "pathId": "9B88047C891952D8A661F30A8E7C0A5842AB8544", "segmentId": 0, "segmentLogicalId": "cd948075-e95f-4c7c-beb2-0fcde7e17c62", "l7_check": "UP", "l7_check_rtt": { "max": 16, "avg": 6, "min": 5 }, "site": { "id": 60282, "logicalId": "717f67c5-7426-4689-a74c-b58c93d4c3b1", "data": { "customSourceIp": "", "linkInternalLogicalId": "00000005-bf16-4512-b490-2dc5c45e11b8", "primaryAddressing": { "internalRouterIp": "172.22.60.145", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.146", "internalZenMask": "255.255.255.255" }, "secondaryAddressing": { "internalRouterIp": "172.22.60.149", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.150", "internalZenMask": "255.255.255.255" }, "useCustomSourceIp": false } }, "provider": { "name": "L7HC-LON3-MAN1-GRE", "id": 549697, "logicalId": "d5a058dc-6202-494c-b65d-6a8c273ed1c4", "data": { "primaryServer": "165.225.16.236", "secondaryServer": "165.225.196.39", "automateDeployment": false, "enableTunnels": true, "sharedIkeAuth": false, "maxTunnelsPerIkeIdentity": 128, "l7HealthCheck": { "enabled": true, "probeIntervalSec": 5, "numOfRetries": 3, "rttThresholdMs": 3000, "cloud": "zscloud.net" }, "provider": "zscalerWebSecurityService" } }, "segmentName": "Global Segment", "interface": "GE6" }, { "state": "UP", "timestamp": "2021-10-04T14:01:50.638Z", "link": "00000006-bf16-4512-b490-2dc5c45e11b8", "local_interface_ip": "172.16.1.1", "local_public_ip": "217.38.39.41", "nvs_ip": "165.225.16.236", "pathId": "DB965CA91A564DE09027F8D766F92CD0DDB54405", "segmentId": 0, "segmentLogicalId": "cd948075-e95f-4c7c-beb2-0fcde7e17c62", "l7_check": "UP", "l7_check_rtt": { "max": 1063, "avg": 41, "min": 5 }, "site": { "id": 60282, "logicalId": "717f67c5-7426-4689-a74c-b58c93d4c3b1", "data": { "customSourceIp": "", "linkInternalLogicalId": "00000005-bf16-4512-b490-2dc5c45e11b8", "primaryAddressing": { "internalRouterIp": "172.22.60.145", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.146", "internalZenMask": "255.255.255.255" }, "secondaryAddressing": { "internalRouterIp": "172.22.60.149", "internalRouterMask": "255.255.255.255", "internalZenIp": "172.22.60.150", "internalZenMask": "255.255.255.255" }, "useCustomSourceIp": false } }, "provider": { "name": "L7HC-LON3-MAN1-GRE", "id": 549697, "logicalId": "d5a058dc-6202-494c-b65d-6a8c273ed1c4", "data": { "primaryServer": "165.225.16.236", "secondaryServer": "165.225.196.39", "automateDeployment": false, "enableTunnels": true, "sharedIkeAuth": false, "maxTunnelsPerIkeIdentity": 128, "l7HealthCheck": { "enabled": true, "probeIntervalSec": 5, "numOfRetries": 3, "rttThresholdMs": 3000, "cloud": "zscloud.net" }, "provider": "zscalerWebSecurityService" } }, "segmentName": "Global Segment", "interface": "GE6" }] }];
//Function to find distinct valies of an object array with specific key
function distinct(dataArray, key) {
var distinctList = [];
dataArray.forEach(function (node) {
if (distinctList.indexOf(node[key]) === -1) {
distinctList.push(node[key]);
}
});
return distinctList;
}
// Reference https://stackoverflow.com/a/34710102/6099327
function _objectWithoutProperties(obj, keys) {
var target = {};
for (var i in obj) {
if (keys.indexOf(i) >= 0) {
continue;
}
if (!Object.prototype.hasOwnProperty.call(obj, i)) {
continue;
}
target[i] = obj[i];
}
return target;
}
var parsedOutput = [];
data.forEach(function (dataNode) {
var distinctInterfaces = distinct(dataNode.cloudServices, "interface");
var remainingProperties = _objectWithoutProperties(dataNode, ["cloudServices"]);
var output = remainingProperties;
distinctInterfaces.forEach(function (interface) {
output[interface] = dataNode.cloudServices.filter(function (node) {
return node.interface === interface;
});
});
parsedOutput.push(output);
});
console.log(parsedOutput);
ES6 Implementation will be a little more easy
const data = [{"id":14042,"created":"2020-03-18T10:11:40.000Z","enterpriseId":437,"siteId":6302,"activationKey":"PMZP-NGRU-HE64-SA5M","activationKeyExpires":"2021-08-04T16:21:33.000Z","activationState":"ACTIVATED","activationTime":"2020-03-18T17:05:27.000Z","softwareVersion":"4.3.0","buildNumber":"R430-20210720-GA-64951-67694-6911a00421","factorySoftwareVersion":"3.3.0","factoryBuildNumber":"R330-MTHD-20190328-GA","softwareUpdated":"2021-09-24T11:21:49.000Z","selfMacAddress":"50:9a:4c:e4:1e:c0","deviceId":"93AB7D33-87B7-42AA-BC0B-7D8255E069AD","logicalId":"d25a6121-bf16-4512-b490-2dc5c45e11b8","serialNumber":"F0TFXC2","modelNumber":"edge610","deviceFamily":"EDGE6X0","name":"SDALM-BAYNARD-LAB-4","dnsName":null,"description":"Dual Internet Site in Baynard","alertsEnabled":1,"operatorAlertsEnabled":1,"edgeState":"CONNECTED","edgeStateTime":"2021-09-24T11:23:00.000Z","isLive":0,"systemUpSince":"2021-09-24T11:20:55.000Z","serviceUpSince":"2021-09-24T11:31:06.000Z","lastContact":"2021-10-04T14:06:47.000Z","serviceState":"IN_SERVICE","endpointPkiMode":"CERTIFICATE_REQUIRED","haState":"UNCONFIGURED","haPreviousState":"UNCONFIGURED","haLastContact":"0000-00-00 00:00:00","haSerialNumber":null,"bastionState":"UNCONFIGURED","modified":"2021-10-04T14:06:47.000Z","customInfo":"","isHub":false,"cloudServices":[{"state":"UP","timestamp":"2021-10-04T14:01:50.638Z","link":"00000005-bf16-4512-b490-2dc5c45e11b8","local_interface_ip":"172.16.2.1","local_public_ip":"217.38.39.43","nvs_ip":"165.225.16.236","pathId":"211262ED9DE488A22CFEBBA9809092B32B937912","segmentId":0,"segmentLogicalId":"cd948075-e95f-4c7c-beb2-0fcde7e17c62","l7_check":"UP","l7_check_rtt":{"max":11,"avg":7,"min":5},"site":{"id":60282,"logicalId":"717f67c5-7426-4689-a74c-b58c93d4c3b1","data":{"customSourceIp":"","linkInternalLogicalId":"00000005-bf16-4512-b490-2dc5c45e11b8","primaryAddressing":{"internalRouterIp":"172.22.60.145","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.146","internalZenMask":"255.255.255.255"},"secondaryAddressing":{"internalRouterIp":"172.22.60.149","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.150","internalZenMask":"255.255.255.255"},"useCustomSourceIp":false}},"provider":{"name":"L7HC-LON3-MAN1-GRE","id":549697,"logicalId":"d5a058dc-6202-494c-b65d-6a8c273ed1c4","data":{"primaryServer":"165.225.16.236","secondaryServer":"165.225.196.39","automateDeployment":false,"enableTunnels":true,"sharedIkeAuth":false,"maxTunnelsPerIkeIdentity":128,"l7HealthCheck":{"enabled":true,"probeIntervalSec":5,"numOfRetries":3,"rttThresholdMs":3000,"cloud":"zscloud.net"},"provider":"zscalerWebSecurityService"}},"segmentName":"Global Segment","interface":"GE5"},{"state":"STANDBY","timestamp":"2021-10-04T14:01:50.638Z","link":"00000005-bf16-4512-b490-2dc5c45e11b8","local_interface_ip":"172.16.2.1","local_public_ip":"217.38.39.43","nvs_ip":"165.225.196.39","pathId":"26434D16946CFD147D5DDFA50647F48A0066AB31","segmentId":0,"segmentLogicalId":"cd948075-e95f-4c7c-beb2-0fcde7e17c62","l7_check":"UP","l7_check_rtt":{"max":10,"avg":6,"min":5},"site":{"id":60282,"logicalId":"717f67c5-7426-4689-a74c-b58c93d4c3b1","data":{"customSourceIp":"","linkInternalLogicalId":"00000005-bf16-4512-b490-2dc5c45e11b8","primaryAddressing":{"internalRouterIp":"172.22.60.145","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.146","internalZenMask":"255.255.255.255"},"secondaryAddressing":{"internalRouterIp":"172.22.60.149","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.150","internalZenMask":"255.255.255.255"},"useCustomSourceIp":false}},"provider":{"name":"L7HC-LON3-MAN1-GRE","id":549697,"logicalId":"d5a058dc-6202-494c-b65d-6a8c273ed1c4","data":{"primaryServer":"165.225.16.236","secondaryServer":"165.225.196.39","automateDeployment":false,"enableTunnels":true,"sharedIkeAuth":false,"maxTunnelsPerIkeIdentity":128,"l7HealthCheck":{"enabled":true,"probeIntervalSec":5,"numOfRetries":3,"rttThresholdMs":3000,"cloud":"zscloud.net"},"provider":"zscalerWebSecurityService"}},"segmentName":"Global Segment","interface":"GE5"},{"state":"STANDBY","timestamp":"2021-10-04T14:01:50.638Z","link":"00000006-bf16-4512-b490-2dc5c45e11b8","local_interface_ip":"172.16.1.1","local_public_ip":"217.38.39.41","nvs_ip":"165.225.196.39","pathId":"9B88047C891952D8A661F30A8E7C0A5842AB8544","segmentId":0,"segmentLogicalId":"cd948075-e95f-4c7c-beb2-0fcde7e17c62","l7_check":"UP","l7_check_rtt":{"max":16,"avg":6,"min":5},"site":{"id":60282,"logicalId":"717f67c5-7426-4689-a74c-b58c93d4c3b1","data":{"customSourceIp":"","linkInternalLogicalId":"00000005-bf16-4512-b490-2dc5c45e11b8","primaryAddressing":{"internalRouterIp":"172.22.60.145","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.146","internalZenMask":"255.255.255.255"},"secondaryAddressing":{"internalRouterIp":"172.22.60.149","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.150","internalZenMask":"255.255.255.255"},"useCustomSourceIp":false}},"provider":{"name":"L7HC-LON3-MAN1-GRE","id":549697,"logicalId":"d5a058dc-6202-494c-b65d-6a8c273ed1c4","data":{"primaryServer":"165.225.16.236","secondaryServer":"165.225.196.39","automateDeployment":false,"enableTunnels":true,"sharedIkeAuth":false,"maxTunnelsPerIkeIdentity":128,"l7HealthCheck":{"enabled":true,"probeIntervalSec":5,"numOfRetries":3,"rttThresholdMs":3000,"cloud":"zscloud.net"},"provider":"zscalerWebSecurityService"}},"segmentName":"Global Segment","interface":"GE6"},{"state":"UP","timestamp":"2021-10-04T14:01:50.638Z","link":"00000006-bf16-4512-b490-2dc5c45e11b8","local_interface_ip":"172.16.1.1","local_public_ip":"217.38.39.41","nvs_ip":"165.225.16.236","pathId":"DB965CA91A564DE09027F8D766F92CD0DDB54405","segmentId":0,"segmentLogicalId":"cd948075-e95f-4c7c-beb2-0fcde7e17c62","l7_check":"UP","l7_check_rtt":{"max":1063,"avg":41,"min":5},"site":{"id":60282,"logicalId":"717f67c5-7426-4689-a74c-b58c93d4c3b1","data":{"customSourceIp":"","linkInternalLogicalId":"00000005-bf16-4512-b490-2dc5c45e11b8","primaryAddressing":{"internalRouterIp":"172.22.60.145","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.146","internalZenMask":"255.255.255.255"},"secondaryAddressing":{"internalRouterIp":"172.22.60.149","internalRouterMask":"255.255.255.255","internalZenIp":"172.22.60.150","internalZenMask":"255.255.255.255"},"useCustomSourceIp":false}},"provider":{"name":"L7HC-LON3-MAN1-GRE","id":549697,"logicalId":"d5a058dc-6202-494c-b65d-6a8c273ed1c4","data":{"primaryServer":"165.225.16.236","secondaryServer":"165.225.196.39","automateDeployment":false,"enableTunnels":true,"sharedIkeAuth":false,"maxTunnelsPerIkeIdentity":128,"l7HealthCheck":{"enabled":true,"probeIntervalSec":5,"numOfRetries":3,"rttThresholdMs":3000,"cloud":"zscloud.net"},"provider":"zscalerWebSecurityService"}},"segmentName":"Global Segment","interface":"GE6"}]}];
const parsedOutput = data.map((node) => {
const { cloudServices, ...otherNodes } = node;
const uniqueInterfaces = [ ...new Set(cloudServices.map(service => service.interface)) ];
interfaceObj = uniqueInterfaces.reduce((acc, curr) => {
acc[curr] = cloudServices.filter((node) => node.interface === curr);
return acc;
}, {})
return { ...otherNodes, ...interfaceObj };
});
console.log(parsedOutput)

Javascript Map through Array of Objects

I am able to print out tmdb_popularity but unable to map/print out with provider(netflix).
I believe I am mapping through {} incorrectly.
movie.offers[0].provider_id failed as well.
Also, is there a way to map out only scoring by 'provider_type:tmdb:score' > 8 for example?
Since tmdb:score is Object.value instead of key is it not feasible?
Thank you.
const JustWatch = require ("justwatch-api")
const netflixId = 8;
function print_result (name, result) {
console.log(name+":");
console.log(JSON.stringify(result, null, 4));
console.log("\n\n\n\n");
}
(async function(){
var justwatch = new JustWatch();
var searchResult = await justwatch.search('a');
searchResult.items.map(function(movie){
if(movie.offers.provider_id == netflixId){
print_result("search", searchResult)
}
})
searchResult.items.map(function(movie){
if(movie.tmdb_popularity > 20){
print_result("search",searchResult)
}
})
}) ();
What the JSON data looks like from (JustWatch API)
{
"total_results": 27468,
"items": [
{
"jw_entity_id": "ts80908",
"id": 80908,
"title": "A Very English Scandal",
"tmdb_popularity": 3.422,
"object_type": "show",
"offers": [
{
"type": "aggregated",
"monetization_type": "flatrate",
"provider_id": 9,
"currency": "USD",
"urls": {
"standard_web": "https://www.amazon.com/gp/product/B07DX9DKP5?camp=1789&creativeASIN=B07DX9DKP5&ie=UTF8&linkCode=xm2&tag=justwatch09-20",
"deeplink_android_tv": "intent://watch.amazon.com/watch?asin=B07DX9DKP5&time=0&territory=US#Intent;package=com.amazon.amazonvideo.livingroom;scheme=https;end"
},
"subtitle_languages": [
"en"
],
"presentation_type": "sd",
"element_count": 1,
"new_element_count": 1,
"date_provider_id": "2019-09-14_9",
"date_created": "2019-09-14"
},
{
"type": "aggregated",
"monetization_type": "flatrate",
"provider_id": 9,
"currency": "USD",
"urls": {
"standard_web": "https://www.amazon.com/gp/product/B07DX9DKP5?camp=1789&creativeASIN=B07DX9DKP5&ie=UTF8&linkCode=xm2&tag=justwatch09-20",
"deeplink_android_tv": "intent://watch.amazon.com/watch?asin=B07DX9DKP5&time=0&territory=US#Intent;package=com.amazon.amazonvideo.livingroom;scheme=https;end"
},
"subtitle_languages": [
"en"
],
"presentation_type": "hd",
"element_count": 1,
"new_element_count": 1,
"date_provider_id": "2019-09-14_9",
"date_created": "2019-09-14"
},
{
"type": "aggregated",
"monetization_type": "flatrate",
"provider_id": 9,
"currency": "USD",
"urls": {
"standard_web": "https://www.amazon.com/gp/product/B07DX8CSSQ?camp=1789&creativeASIN=B07DX8CSSQ&ie=UTF8&linkCode=xm2&tag=justwatch09-20",
"deeplink_android_tv": "intent://watch.amazon.com/watch?asin=B07DX8CSSQ&time=0&territory=US#Intent;package=com.amazon.amazonvideo.livingroom;scheme=https;end",
"deeplink_fire_tv": "intent://com.amazon.tv.launcher/detail?provider=aiv&providerId=B07DX8CSSQ#Intent;package=com.amazon.tv.launcher;scheme=amzn;end",
"deeplink_tvos": "aiv://aiv/watch?asin=B07DX8CSSQ&territory=US&time=auto"
},
"subtitle_languages": [
"en"
],
"presentation_type": "4k",
"element_count": 1,
"new_element_count": 1,
"date_provider_id": "2019-09-06_9",
"date_created": "2019-09-06"
}
],
"scoring": [
{
"provider_type": "tmdb:score",
"value": 8.1
},
{
"provider_type": "imdb:score",
"value": 7.8
},
{
"provider_type": "tmdb:popularity",
"value": 3.422
}
]
},
{
"jw_entity_id": "tm205151",
"id": 205151,
"title": "Alpha",
"full_path": "/us/movie/alpha-2015",
"full_paths": {
"MOVIE_DETAIL_OVERVIEW": "/us/movie/alpha-2015"
},
"poster": "/poster/139203407/{profile}",
"original_release_year": 2015,
"tmdb_popularity": 0.878,
"object_type": "movie",
"offers": [
{
"monetization_type": "flatrate",
"provider_id": 25,
"urls": {
"standard_web": "https://www.fandor.com/films/alpha"
},
"presentation_type": "hd",
"date_provider_id": "2016-06-13_25",
"date_created": "2016-06-13"
},
{
"monetization_type": "flatrate",
"provider_id": 25,
"urls": {
"standard_web": "https://www.fandor.com/films/alpha"
},
"presentation_type": "sd",
"date_provider_id": "2016-06-13_25",
"date_created": "2016-06-13"
},
{
"monetization_type": "flatrate",
"provider_id": 199,
"currency": "USD",
"urls": {
"standard_web": "https://www.amazon.com/gp/product/B01M7O3UQU?camp=1789&creativeASIN=B01M7O3UQU&ie=UTF8&linkCode=xm2&tag=justwatch09-20",
"deeplink_android_tv": "intent://watch.amazon.com/watch?asin=B01M7O3UQU&time=0&territory=US#Intent;package=com.amazon.amazonvideo.livingroom;scheme=https;end",
"deeplink_fire_tv": "intent://com.amazon.tv.launcher/detail?provider=aiv&providerId=B01M7O3UQU#Intent;package=com.amazon.tv.launcher;scheme=amzn;end",
"deeplink_tvos": "aiv://aiv/watch?asin=B01M7O3UQU&territory=US&time=auto"
},
"presentation_type": "sd",
"date_provider_id": "2019-06-19_199",
"date_created": "2019-06-19"
}
],
"scoring": [
{
"provider_type": "tmdb:popularity",
"value": 0.878
},
{
"provider_type": "tmdb:id",
"value": 333465
},
{
"provider_type": "tmdb:score",
"value": 7
},
{
"provider_type": "imdb:score",
"value": 7.7
}
]
},
....
Here Try this
searchResult.items.map(function(movie){
movie.offers.forEach(offer => {
if(offer.provider_id == netflixId){
print_result("search", searchResult)
}
})
})
forEach is better here instead of map as you are not returning in map function. Use find function to search for offer.
searchResult.items.forEach(function(movie) {
const offer = movie.offers.find(offer => offer.provider_id == netflixId);
if(offer){
print_result("search", movie)
print_result("offer", offer)
}
})

Need to get Name, Node Name and Phase Values from API

I am trying to get Name, Node Name and Phase values from JSON Data using JavaScript. Here is my JavaScript
<script>
$(document).ready(function () {
$.getJSON('http://ec2-3-82-117-70.compute-1.amazonaws.com:8080/api/v0/retrievePodStatus/default',
function (data) {
console.log(data)
document.body.append("Name: " + data.items[1].metadata.name);
// document.body.append(data.items[1].metadata.name);
// document.body.append(data.items[0].spec.nodeName);
});
});
</script>
I am just getting the name in here. Can someone please help me how to get Name, Node Name and Phase Values? find the below JSON as well.
"apiVersion": "v1",
"items": [
{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"annotations": {
"kubernetes.io/limit-ranger": "LimitRanger plugin set: cpu request for container external-dns"
},
"creationTimestamp": "2019-02-28T16:22:49Z",
"generateName": "external-dns-5d69b66646-",
"labels": {
"app": "external-dns",
"pod-template-hash": "1825622202"
},
"name": "external-dns-5d69b66646-pmxmd",
"namespace": "default",
"ownerReferences": [
{
"apiVersion": "extensions/v1beta1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "ReplicaSet",
"name": "external-dns-5d69b66646",
"uid": "170d9260-3b75-11e9-abe2-0ec5819342ce"
}
],
"resourceVersion": "2984",
"selfLink": "/api/v1/namespaces/default/pods/external-dns-5d69b66646-pmxmd",
"uid": "170e1a0d-3b75-11e9-abe2-0ec5819342ce"
},
"spec": {
"containers": [
{
"args": [
"--source=service",
"--source=ingress",
"--provider=aws",
"--registry=txt",
"--txt-owner-id=qpair"
],
"image": "registry.opensource.zalan.do/teapot/external-dns:v0.4.2",
"imagePullPolicy": "IfNotPresent",
"name": "external-dns",
"resources": {
"requests": {
"cpu": "100m"
}
},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [
{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"name": "default-token-rr546",
"readOnly": true
}
]
}
],
"dnsPolicy": "ClusterFirst",
"nodeName": "ip-172-20-39-147.ec2.internal",
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"serviceAccount": "default",
"serviceAccountName": "default",
"terminationGracePeriodSeconds": 30,
"tolerations": [
{
"effect": "NoExecute",
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"tolerationSeconds": 300
},
{
"effect": "NoExecute",
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"tolerationSeconds": 300
}
],
"volumes": [
{
"name": "default-token-rr546",
"secret": {
"defaultMode": 420,
"secretName": "default-token-rr546"
}
}
]
},
"status": {
"conditions": [
{
"lastProbeTime": null,
"lastTransitionTime": "2019-02-28T16:22:49Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-02-28T16:22:58Z",
"status": "True",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-02-28T16:22:49Z",
"status": "True",
"type": "PodScheduled"
}
],
"containerStatuses": [
{
"containerID": "docker://18b96317cf360d562fb3f849c6716c50a41a67a4dbc126164020531e1e4d84a9",
"image": "registry.opensource.zalan.do/teapot/external-dns:v0.4.2",
"imageID": "docker-pullable://registry.opensource.zalan.do/teapot/external-dns#sha256:d54b9eb8948b87eb7fcd938990ff2dbc9ca0a42d9c5d36fcaa75c7cf066f7995",
"lastState": {},
"name": "external-dns",
"ready": true,
"restartCount": 0,
"state": {
"running": {
"startedAt": "2019-02-28T16:22:57Z"
}
}
}
],
"hostIP": "172.20.39.147",
"phase": "Running",
"podIP": "100.96.7.3",
"qosClass": "Burstable",
"startTime": "2019-02-28T16:22:49Z"
}
},
I am just getting the name in here. Can someone please help me how to get Name, Node Name and Phase Values? find the below JSON as well.
Thanks, Much Appreciated
You were close with the code you posted. You just needed items[0] instead of items[1]. Remember the first element of an array is always 0. Other than that its as easy as checking the open and close brackets [] or {} to see where each nested object/array starts and ends.
Code:
var name = data.items[0].metadata.name
var nodeName = data.items[0].spec.nodeName
var phase = data.items[0].status.phase
snippet:
var data = {
"apiVersion": "v1",
"items": [{
"apiVersion": "v1",
"kind": "Pod",
"metadata": {
"annotations": {
"kubernetes.io/limit-ranger": "LimitRanger plugin set: cpu request for container external-dns"
},
"creationTimestamp": "2019-02-28T16:22:49Z",
"generateName": "external-dns-5d69b66646-",
"labels": {
"app": "external-dns",
"pod-template-hash": "1825622202"
},
"name": "external-dns-5d69b66646-pmxmd",
"namespace": "default",
"ownerReferences": [{
"apiVersion": "extensions/v1beta1",
"blockOwnerDeletion": true,
"controller": true,
"kind": "ReplicaSet",
"name": "external-dns-5d69b66646",
"uid": "170d9260-3b75-11e9-abe2-0ec5819342ce"
}],
"resourceVersion": "2984",
"selfLink": "/api/v1/namespaces/default/pods/external-dns-5d69b66646-pmxmd",
"uid": "170e1a0d-3b75-11e9-abe2-0ec5819342ce"
},
"spec": {
"containers": [{
"args": [
"--source=service",
"--source=ingress",
"--provider=aws",
"--registry=txt",
"--txt-owner-id=qpair"
],
"image": "registry.opensource.zalan.do/teapot/external-dns:v0.4.2",
"imagePullPolicy": "IfNotPresent",
"name": "external-dns",
"resources": {
"requests": {
"cpu": "100m"
}
},
"terminationMessagePath": "/dev/termination-log",
"terminationMessagePolicy": "File",
"volumeMounts": [{
"mountPath": "/var/run/secrets/kubernetes.io/serviceaccount",
"name": "default-token-rr546",
"readOnly": true
}]
}],
"dnsPolicy": "ClusterFirst",
"nodeName": "ip-172-20-39-147.ec2.internal",
"restartPolicy": "Always",
"schedulerName": "default-scheduler",
"securityContext": {},
"serviceAccount": "default",
"serviceAccountName": "default",
"terminationGracePeriodSeconds": 30,
"tolerations": [{
"effect": "NoExecute",
"key": "node.kubernetes.io/not-ready",
"operator": "Exists",
"tolerationSeconds": 300
},
{
"effect": "NoExecute",
"key": "node.kubernetes.io/unreachable",
"operator": "Exists",
"tolerationSeconds": 300
}
],
"volumes": [{
"name": "default-token-rr546",
"secret": {
"defaultMode": 420,
"secretName": "default-token-rr546"
}
}]
},
"status": {
"conditions": [{
"lastProbeTime": null,
"lastTransitionTime": "2019-02-28T16:22:49Z",
"status": "True",
"type": "Initialized"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-02-28T16:22:58Z",
"status": "True",
"type": "Ready"
},
{
"lastProbeTime": null,
"lastTransitionTime": "2019-02-28T16:22:49Z",
"status": "True",
"type": "PodScheduled"
}
],
"containerStatuses": [{
"containerID": "docker://18b96317cf360d562fb3f849c6716c50a41a67a4dbc126164020531e1e4d84a9",
"image": "registry.opensource.zalan.do/teapot/external-dns:v0.4.2",
"imageID": "docker-pullable://registry.opensource.zalan.do/teapot/external-dns#sha256:d54b9eb8948b87eb7fcd938990ff2dbc9ca0a42d9c5d36fcaa75c7cf066f7995",
"lastState": {},
"name": "external-dns",
"ready": true,
"restartCount": 0,
"state": {
"running": {
"startedAt": "2019-02-28T16:22:57Z"
}
}
}],
"hostIP": "172.20.39.147",
"phase": "Running",
"podIP": "100.96.7.3",
"qosClass": "Burstable",
"startTime": "2019-02-28T16:22:49Z"
}
}],
}
var name = data.items[0].metadata.name
var nodeName = data.items[0].spec.nodeName
var phase = data.items[0].status.phase
console.log(name)
console.log(nodeName)
console.log(phase)

Javascript: Loop through nested objects and arrays

I have an server response with data which has the structur as you can see in the codesnippet.
My goal is to iterate through each consent and add the channels
The data from the response:
[
{
"consents": [
{
"channels": [
{
"granted": true,
"id": "sms",
"title": "SMS/MMS"
},
{
"granted": true,
"id": "email",
"title": "E-Mail"
},
{
"granted": false,
"id": "phone",
"title": "Telefon"
},
{
"granted": false,
"id": "letter",
"title": "Brief"
}
],
"client": "App",
"configId": "99df8e86-2e24-4974-80da-74f901ba6a0d",
"date": "2018-03-08T16:03:25.753Z",
"granted": true,
"name": "bestandsdaten-alle-produkte",
"version": "1.0.0",
"versionId": "bd002dcd-fee6-42f8-aafe-22d0209a0646"
}
],
"createdAt": "2018-03-08T16:03:25.778Z",
"id": "1b9649a6-d8de-45c6-a0ae-a03cecf71cb5",
"updatedAt": "2018-03-08T16:03:25.778Z",
"username": "demo-app"
},
{
"consents": [
{
"channels": [
{
"granted": true,
"id": "sms",
"title": "SMS/MMS"
},
{
"granted": true,
"id": "email",
"title": "E-Mail"
},
{
"granted": true,
"id": "phone",
"title": "Telefon"
},
{
"granted": true,
"id": "letter",
"title": "Brief"
}
],
"client": "App",
"configId": "99df8e86-2e24-4974-80da-74f901ba6a0d",
"date": "2018-03-08T14:51:52.188Z",
"granted": true,
"name": "bestandsdaten-alle-produkte",
"version": "1.0.0",
"versionId": "bd002dcd-fee6-42f8-aafe-22d0209a0646"
}
],
"createdAt": "2018-03-08T14:51:52.208Z",
"id": "cf550425-990e-45ef-aaee-eced95d8fa08",
"updatedAt": "2018-03-08T14:51:52.208Z",
"username": "demo-app"
},
{
"consents": [
{
"channels": [
{
"granted": false,
"id": "sms",
"title": "SMS/MMS"
},
{
"granted": true,
"id": "email",
"title": "E-Mail"
},
{
"granted": true,
"id": "phone",
"title": "Telefon"
},
{
"granted": false,
"id": "letter",
"title": "Brief"
}
],
"client": "App",
"configId": "99df8e86-2e24-4974-80da-74f901ba6a0d",
"date": "2018-03-08T14:48:27.024Z",
"granted": true,
"name": "bestandsdaten-alle-produkte",
"version": "1.0.0",
"versionId": "bd002dcd-fee6-42f8-aafe-22d0209a0646"
}
],
"createdAt": "2018-03-08T14:48:27.054Z",
"id": "7fc1f087-2139-4494-bad7-161b0c6231a9",
"updatedAt": "2018-03-08T14:48:27.054Z",
"username": "demo-app"
},
]
The way i go is the following. But i need a way to append the channels to each Consent. Is there a way to solve this?
consentsList.forEach((consent, index, array) => {
consent.consents.forEach((c) => {
Object.keys(c).forEach((key) => {
dd.content.push(
{
columns: [
{
text: `${key}: `, style: 'text'
},
{
text: c[key], style: 'text'
}
]
}
);
});
});
Consents.push(consent);
if (index !== array.length - 1) {
dd.content.push({
margin: [0, 0, 0, 5],
canvas: [{
type: 'line', x1: 0, y1: 5, x2: 595 - (2 * 40), y2: 5, lineWidth: 0.6
}]
});
}
});
I want to output the individual channels where channels is on the top of each entry
You can extract the titles using map. And concantanate them using join like this.
let value = "";
if(key === "channels"){
value = c[key].map(x => x.title).join(" ,");
}
else {
value = c[key];
}
columns: [
{
text: `${key}: `, style: 'text'
},
{
text: value, style: 'text'
}
]
I have written a piece of code, hope this is what you're looking for. It is not optimized, try to optimize at your will
var a = responseData;
a.forEach(function(items) {
var allChannels = [];
items.consents.forEach(function(innerItems){
innerItems.channels.forEach(function(value){
allChannels.push(value.title);
})
items.allChannels = allChannels.join();
})
});
console.log(a);

Categories

Resources