node red function add and remove object from context array - arrays

I have a for loop in the node red function that a the start of the function I get the array from the context
var alarmArray = flow.get("alarmArray")
and after I need to push object on the array I have do this but I'm not pusching on the flow context array but in the local array
alarmArray.push({
key: "Low air pressure",
value: alarm1Cip
});
flow.set("alarm1CipOld",alarm1Cip);
and after in the for loop I need to remove the object from the context but in my way I remove it from local array
for (var key in alarmArray){
node.warn(key);
msg.payload = {
"title": alarmArray[key].key,
"isActive":alarmArray[key].value
};
node.send(msg)
delete alarmArray[key]
}
how can I manage to add and remove object in the context array?
thanks

The problem here is that NodeJS is a pass by reference language. This means that there are not 2 arrays here, only 1 that has 2 handles (var alarmArray and flow.get('alarmArray'))
This means that anything pushed/deleted on the "local" copy is also getting pushed/deleted to the copy in the context.
The only way to do what you want will be to make a deep copy of the array every time you recover it from the context and then work on the copy locally.
Assuming the array only holds simple objects then the following should work:
var alarmArray = JSON.parse(JSON.stringify(flow.get('alarmArray')))

If you want to save your changes you just have to reload the mutated object in the right context, overwriting the previous value with
flow.set('alarmArray', alarmArray)

You might better to use global.set instead of flow.set
This might help you.
[
{
"id": "133329daaceb6bb3",
"type": "tab",
"label": "flow 3",
"disabled": false,
"info": "",
"env": []
},
{
"id": "c80bec9a15b703f6",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 140,
"wires": [
[
"8687551e01cd2045"
]
]
},
{
"id": "8687551e01cd2045",
"type": "function",
"z": "133329daaceb6bb3",
"name": "msg_1",
"func": "global.set(\"msg_1\",\"test\");\n\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 280,
"y": 140,
"wires": [
[]
]
},
{
"id": "103b03c39c8d9cae",
"type": "debug",
"z": "133329daaceb6bb3",
"name": "debug 29",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 500,
"y": 300,
"wires": []
},
{
"id": "c043cba9f34ba574",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 180,
"wires": [
[
"e674c706437cc0f3"
]
]
},
{
"id": "e674c706437cc0f3",
"type": "function",
"z": "133329daaceb6bb3",
"name": "msg_2 ",
"func": "global.set(\"msg_2\",\"hello\");\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 280,
"y": 180,
"wires": [
[]
]
},
{
"id": "11f8fb75d4c4e6c0",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "1",
"crontab": "",
"once": true,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 150,
"y": 300,
"wires": [
[
"1346e34e8c83b2dc"
]
]
},
{
"id": "1346e34e8c83b2dc",
"type": "function",
"z": "133329daaceb6bb3",
"name": "check if 2 msg set",
"func": "var msg1 = global.get(\"msg_1\");\nvar msg2 = global.get(\"msg_2\");\n\nif(msg1 && msg2){\n msg.payload=\"both message arrived!\";\n}\nelse{\n msg.payload=\"Nope. Not yet.\";\n}\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 330,
"y": 300,
"wires": [
[
"103b03c39c8d9cae"
]
]
},
{
"id": "62d522a844321ef9",
"type": "inject",
"z": "133329daaceb6bb3",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 540,
"y": 140,
"wires": [
[
"6d109daff443dade"
]
]
},
{
"id": "6d109daff443dade",
"type": "function",
"z": "133329daaceb6bb3",
"name": "reset",
"func": "global.set(\"msg_1\",null);\nglobal.set(\"msg_2\",null);\nreturn msg;",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 690,
"y": 140,
"wires": [
[]
]
},
{
"id": "4e1848c867860d5f",
"type": "comment",
"z": "133329daaceb6bb3",
"name": "Here gonna auto-run",
"info": "",
"x": 170,
"y": 260,
"wires": []
},
{
"id": "3102e176923a8fad",
"type": "comment",
"z": "133329daaceb6bb3",
"name": "Check what if both inject clicked",
"info": "",
"x": 210,
"y": 100,
"wires": []
}
]

Related

While Loop in Node Red

I have one system that is connected to some sensors. The main job is to send error numbers when one or more of the sensors are on.
In order to print the error description I have one csv-File with two columns, the first one with the numbers and the second one with the description.
In order to make this task I have created one flow in Node-Red:
In one line I save the array with the error numbers coming from the system in one flow variable (RandomNum).
In another line I read the csv-file with the error description, I transform it in an array of objects and then in fuction node I make a search in order to find the error number and the description.
The search function has as entance the array of objects. I save the flow variable (RandomNum) in an array (ranNum) and I define a new array (newMsg) where I save the description of the errors.
Then I use a while-loop in order to go through the array of objects and compare the value of the first column of this array with the number in ranNum. Then I save the description of the error in the array newMsg and I do this while-loop for each value of the ranNum array.
And here is my problem. When I execute the flow, it works correctly for the first value of the array ranNum but only for this. I get only the description of the first number in the ranNum array as payload, it looks like as the while-loop is used only once, and then it breaks and gives me the array newMsg.
When I check in the Conetxt, RandomNum is one array,
An when I ask to get the array ranNum, it's also an array,
I have check the while-loop at least 20-times, and I have did not found why it does not work.
Can anyone help me with this topic? Is there a problem with the flow variable or there is big difference between JavaScript and NodeJS that I did not found?
Here is the flow I have created:
[
{
"id": "b1d8b61d0ed5a5da",
"type": "tab",
"label": "Flow Test",
"disabled": false,
"info": ""
},
{
"id": "d677b342ccc51f1b",
"type": "inject",
"z": "b1d8b61d0ed5a5da",
"name": "",
"props": [
{
"p": "payload"
},
{
"p": "topic",
"vt": "str"
}
],
"repeat": "",
"crontab": "",
"once": false,
"onceDelay": 0.1,
"topic": "",
"payload": "",
"payloadType": "date",
"x": 140,
"y": 280,
"wires": [
[
"e2d5187d2e705892",
"a167b5a81e0b36ba"
]
]
},
{
"id": "7aa6e0bcbdf67c1c",
"type": "file in",
"z": "b1d8b61d0ed5a5da",
"name": "ReadAlarms",
"filename": "/home/DMT/Dokumente/DB_Test/alarms.csv",
"format": "utf8",
"chunk": false,
"sendError": false,
"encoding": "none",
"allProps": false,
"x": 530,
"y": 280,
"wires": [
[
"f2ab599d26fd7ca5",
"94ae4b1ea29d9fe2"
]
]
},
{
"id": "f2ab599d26fd7ca5",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 750,
"y": 220,
"wires": []
},
{
"id": "94ae4b1ea29d9fe2",
"type": "csv",
"z": "b1d8b61d0ed5a5da",
"name": "ConvertAlarms",
"sep": ",",
"hdrin": false,
"hdrout": "all",
"multi": "mult",
"ret": "\\n",
"temp": "",
"skip": "0",
"strings": true,
"include_empty_strings": "",
"include_null_values": "",
"x": 760,
"y": 280,
"wires": [
[
"9a3547cc81c2d2bb",
"ff9175d01efa5ce4"
]
]
},
{
"id": "9a3547cc81c2d2bb",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": false,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 990,
"y": 220,
"wires": []
},
{
"id": "1a270df6276485c4",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "payload",
"targetType": "msg",
"statusVal": "",
"statusType": "auto",
"x": 1230,
"y": 220,
"wires": []
},
{
"id": "ff9175d01efa5ce4",
"type": "function",
"z": "b1d8b61d0ed5a5da",
"name": "SearchFailureS7",
"func": "let i=0;\nlet ranNum = [];\nranNum = flow.get(\"RandomNum\");\nlet newMsg = [];\n\nwhile (i<ranNum.length){\n\n let n = ranNum[i];\n newMsg[newMsg.length] = {payload: msg.payload[n].col2};\n i = i + 1;\n \n}\n\nreturn newMsg;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 1010,
"y": 280,
"wires": [
[
"1a270df6276485c4"
]
]
},
{
"id": "a167b5a81e0b36ba",
"type": "function",
"z": "b1d8b61d0ed5a5da",
"name": "RandomArray",
"func": "const num=[];\nvar i;\n\nfor (i=0; i<3; i++){\n \nnum[i] = Math.floor(Math.random() * 9);\n\n}\n\nrandArray = {payload: num}\n\nreturn randArray;\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 340,
"y": 400,
"wires": [
[
"c011fa2387db0d18",
"9c400785174973e9"
]
]
},
{
"id": "c011fa2387db0d18",
"type": "debug",
"z": "b1d8b61d0ed5a5da",
"name": "",
"active": true,
"tosidebar": true,
"console": false,
"tostatus": false,
"complete": "false",
"statusVal": "",
"statusType": "auto",
"x": 530,
"y": 340,
"wires": []
},
{
"id": "9c400785174973e9",
"type": "function",
"z": "b1d8b61d0ed5a5da",
"name": "",
"func": "flow.set(\"RandomNum\",msg.payload);\n",
"outputs": 1,
"noerr": 0,
"initialize": "",
"finalize": "",
"libs": [],
"x": 520,
"y": 400,
"wires": [
[]
]
},
{
"id": "e2d5187d2e705892",
"type": "delay",
"z": "b1d8b61d0ed5a5da",
"name": "Delay 10ms",
"pauseType": "delay",
"timeout": "10",
"timeoutUnits": "milliseconds",
"rate": "1",
"nbRateUnits": "1",
"rateUnits": "second",
"randomFirst": "1",
"randomLast": "5",
"randomUnits": "seconds",
"drop": false,
"allowrate": false,
"outputs": 1,
"x": 330,
"y": 280,
"wires": [
[
"7aa6e0bcbdf67c1c"
]
]
}
]
So, I finally found it. The payload in the while-loop was breaking the loop immediately. So I changed the code in the while-loop using a similar code I found on the net. Now it works.
Old code:
let i=0;
let ranNum = [];
ranNum = flow.get("RandomNum");
let newMsg = [];
while (i<ranNum.length){
let n = ranNum[i];
newMsg[newMsg.length] = {payload: msg.payload[n].col2};
i = i + 1;
}
return newMsg;
New code
let i=0;
let ranNum = [];
ranNum = flow.get("RandomNum");
let newMsg = [];
while (i<ranNum.length){
let n = ranNum[i];
let description = msg.payload[n].col2;
newMsg.push(description);
i = i + 1;
}
msg.payload = newMsg;
return msg;

Flutter Create dynamic widget from dynamic json response

companyList = data['fields'][0]['choices'];
if (companyList.length != 0) {
int val;
for (val = 0; val < companyList.length; val++) {
final controller = TextEditingController();
final field = xTextfield(
txtlabel: "Values",
iconfield: bookmarksIcon,
);
setState(() {
_controllers.add(controller);
_fields.add(field);
});
}
}
But this works only if json response is same when it changes and Array object is differnet i got error here is my json that will be different everytime e.g
"inputtype": "dropdown", will make a dropdown widget and all data will be put into it and so on
{ "fields": [ { "id": 31, "name": "make", "isrequired": "required", "valuetype": "text", "priority": 1, "inputtype": "dropdown", "max_min": [], "rangeable": "false", "choices": [ { "id": 46, "name": "Samsung", "categoryextrafield_id": 31, "created_at": "2021-12-29T01:30:47.000000Z", "updated_at": "2021-12-29T01:30:47.000000Z", "priority": 10 }, { "id": 47, "name": "Dell", "categoryextrafield_id": 31, "created_at": "2021-12-29T01:30:52.000000Z", "updated_at": "2021-12-29T01:30:52.000000Z", "priority": 20 }, { "id": 48, "name": "IBM", "categoryextrafield_id": 31, "created_at": "2021-12-29T01:31:09.000000Z", "updated_at": "2021-12-29T01:31:09.000000Z", "priority": 30 }, { "id": 49, "name": "Acer", "categoryextrafield_id": 31, "created_at": "2021-12-29T01:31:24.000000Z", "updated_at": "2021-12-29T01:31:24.000000Z", "priority": 40 } ], "available": [] }, { "id": 32, "name": "model", "isrequired": "required", "valuetype": "text", "priority": 2, "inputtype": "textfield", "max_min": [], "rangeable": "false", "choices": [], "available": [ { "model": "a51" }, { "model": "y9s" }, { "model": "a31" }, { "model": "yS10" }, { "model": "Y10S" }, { "model": "A551" }, { "model": "node8" }, { "model": "s9" }, { "model": null }, { "model": "2021" }, { "model": "2020" }, { "model": "2010" }, { "model": "Civic" }, { "model": "2019" }, { "model": "Daewooy9" }, { "model": "corei5" }, { "model": "corei9" }, { "model": "corei3" }, { "model": "corei11" } ] }, { "id": 29, "name": "features", "isrequired": "required", "valuetype": "text", "priority": 3, "inputtype": "checkbox", "max_min": [], "rangeable": "false", "choices": [ { "id": 41, "name": "Bluetooth", "categoryextrafield_id": 29, "created_at": "2021-12-29T01:19:00.000000Z", "updated_at": "2021-12-29T01:19:00.000000Z", "priority": 1 }, { "id": 42, "name": "Fingerprint", "categoryextrafield_id": 29, "created_at": "2021-12-29T01:19:10.000000Z", "updated_at": "2021-12-29T01:19:10.000000Z", "priority": 10 }, { "id": 43, "name": "LedDisplay", "categoryextrafield_id": 29, "created_at": "2021-12-29T01:19:35.000000Z", "updated_at": "2021-12-29T01:19:35.000000Z", "priority": 15 } ], "available": [] }, { "id": 30, "name": "condition", "isrequired": "required", "valuetype": "text", "priority": 4, "inputtype": "radiobutton", "max_min": [], "rangeable": "false", "choices": [ { "id": 44, "name": "Used", "categoryextrafield_id": 30, "created_at": "2021-12-29T01:20:31.000000Z", "updated_at": "2021-12-29T01:20:31.000000Z", "priority": 10 }, { "id": 45, "name": "New", "categoryextrafield_id": 30, "created_at": "2021-12-29T01:20:38.000000Z", "updated_at": "2021-12-29T01:20:38.000000Z", "priority": 20 } ], "available": [] } ] }
You can use the Dynamic Widget package.
Just pass the widget as JSON data from the server and use a FutureBuilder to build it when your data arrives.
You will also need to change your JSON data accordingly.

Angular - get data from Object Array

Good morning, can anyone advise me? I'm pretty clueless. I've already spent a few hours on it and I don't know how to solve this.
The data is fictitious and the original JSON is far more complex.
JSON
{
"main": [
[
{
"type": "dasdasdasd",
"id": 5,
"content": {
"title": "adadadsad",
"items": [
{
"date": "2012-02-02T11:23:00Z",
"id": 12,
"name": "test",
"isEnabled": false,
"isHighlited": false,
"images": {
"lists": {
"small": [
{
"id": 18,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
],
"original": [
{
"id": 19,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
],
"large": [
{
"id": 22,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
],
"medium": [
{
"id": 23,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
]
}
},
"enum": "LINIE",
"url": "https://test.com"
}
]
}
}
]
],
"second": [
]
}
How can I get from main -> content -> items -> images -> url?
More precisely each images and from that url.
Thank you very much in advance for your help.
It looks like your main array has an array as 1st element. If that is correct, you take the first element of main, and then loop over that.
let jsonObj = {
"main": [
[
{
"type": "dasdasdasd",
"id": 5,
"content": {
"title": "adadadsad",
"items": [
{
"date": "2012-02-02T11:23:00Z",
"id": 12,
"name": "test",
"isEnabled": false,
"isHighlited": false,
"images": {
"lists": {
"small": [
{
"id": 18,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
],
"original": [
{
"id": 19,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
],
"large": [
{
"id": 22,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
],
"medium": [
{
"id": 23,
"position": 0,
"titleImage": true,
"url": "",
"thumbnailReady": true
}
]
}
},
"enum": "LINIE",
"url": "https://test.com"
}
]
}
}
]
],
"second": [
]
}
let smallImg = "", originalImg = "", largeImg = "", mediumImg = "";
jsonObj.main[0].forEach(mainItem => {
mainItem.content.items.forEach(item => {
smallImg = item.images.lists.small[0].url;
originalImg = item.images.lists.original[0].url;
largeImg = item.images.lists.large[0].url;
mediumImg = item.images.lists.medium[0].url;
});
});
console.log(smallImg);
console.log(originalImg);
console.log(largeImg);
console.log(mediumImg);

Jq to add the element in json array conditionally and print the entire modified file

I have a json file with the below format.
I would like to add the element {"test" : "2"}in propDefs[] if the .children[].type=="environmentApprovalTask" and .children[].role.name== "GCM approver" and output that to the new file. I want the entire file with the modified content.The .children[] array may not have always 3 elements.
{
"edges": [
{
"to": "de32e562319310b7b4fe3736e22009",
"from": "99d5f0b278f08721adba7741b782d8",
"type": "SUCCESS",
"value": ""
},
{
"to": "06916609ad7fd4127815be3f075c81",
"from": "de32e562319310b7b4fe3736e22009",
"type": "SUCCESS",
"value": ""
},
{
"to": "99d5f0b278f08721adba7741b782d8",
"type": "ALWAYS",
"value": ""
}
],
"offsets": [
{
"name": "99d5f0b278f08721adba7741b782d8",
"x": -91,
"y": 100,
"h": 70,
"w": 290
},
{
"name": "06916609ad7fd4127815be3f075c81",
"x": -5,
"y": 420,
"h": 80,
"w": 120
},
{
"name": "de32e562319310b7b4fe3736e22009",
"x": 69,
"y": 240,
"h": 70,
"w": 240
}
],
"layoutMode": "manual",
"type": "graph",
"id": "d5d9c4c4-0c5f-4642-872c-ac892039eaa4",
"name": "79e8b952-dd59-4cfd-9c0c-e6c08a81d4ca",
"children": [
{
"type": "finish",
"id": "833e959c-6825-413d-afc4-7b74c0a87c3e",
"name": "06916609ad7fd4127815be3f075c81",
"children": []
},
{
"id": "e976041d-af9d-48cf-b838-735bb5efd483",
"type": "envApprovalTask",
"children": [],
"name": "de32e562319310b7b4fe3736e22009",
"roleRestrictionData": {
"contextType": "ENVIRONMENT",
"roleRestrictions": [
{
"roleId": "087175fb-5d38-42d1-b65a-2b6a6958bc21"
}
]
},
"propDefs": [{"test": "1"}],
"templateName": "ApprovalCreated",
"commentRequired": false,
"commentPrompt": "",
"role": {
"id": "087175fb-5d38-42d1-b65a-2b6a6958bc21",
"name": "Approver",
"isDeletable": true
}
},
{
"id": "513fbc6a-3c4a-4a10-9eb0-7dc893c69413",
"type": "environmentApprovalTask",
"children": [],
"name": "99d5f0b278f08721adba7741b782d8",
"roleRestrictionData": {
"contextType": "ENVIRONMENT",
"roleRestrictions": [
{
"roleId": "116b8cd5-e7e4-403d-9599-35fe25d3cba2"
}
]
},
"propDefs": [],
"templateName": "ApprovalCreated",
"commentRequired": false,
"commentPrompt": "",
"role": {
"id": "116b8cd5-e7e4-403d-9599-35fe25d3cba2",
"name": "Manager Approver",
"isDeletable": true
}
}
]
}
My final attempt with the code
cat file.json |jq '.|.children[]| select(.type=="envApprovalTask")|select(.role.name=="Approver") |.propDefs[.profDefs|length] |= .+ {"test" : "2"}'
This only produces the modified element, didnt produce the entire file as output. Please help how can i get the desired output.
TIL about complex assignments in jq. This actually works:
(.children[] | select(.type=="envApprovalTask" and .role.name=="Approver") | .propDefs) |= .+[{"test":"2"}]
The only significant difference from your version is the parenthesised left side of the assignment.

Join 2 arrays by key and value (AngularJS)

I have 2 objects
{
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true
},
and
{
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": "THIS IS MY REF",
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
},
Object one defines what a field should be and what it is called
The second object is a job description.
What i need is to match a field to each key (this even sounds confusing i my head, so here is an example)
{
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": {
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true,
"value": "THIS IS MY REF"
}
},
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
},
Here you go:
var def = {
"_id": "58b7f36b3354c24630f6f3b0",
"name": "refcode",
"caption": "Reference",
"type": "string",
"search": false,
"required": false,
"table": true,
"expansion": true
};
var jobDesc = {
"_id": "58b7f36b3354c24630f6f3c8",
"vacancyid": "0",
"refcode": "THIS IS MY REF",
"position": "Test",
"jobtype": "Temp",
"department": "Industrial",
"branch": "Office",
"startdate": "02/12/2013",
"contactname": "Person Name",
"contactemail": "person#domain",
"Q_V_TYP": "Daily",
"score": 0
};
var jobDescKeysArr = Object.keys(jobDesc);
if (jobDescKeysArr.indexOf(def.name) !== -1) {
// A match.
def.value = jobDesc[def.name];
jobDesc[def.name] = Object.assign({}, def);
console.log(jobDesc)
}

Resources