# Change an array in a function

**URL:** <https://discourse.nodered.org/t/change-an-array-in-a-function/22292>\
**Category:** General\
**Created:** [26 February 2020 17:40 UTC](https://discourse.nodered.org/t/change-an-array-in-a-function/22292 "2020-02-26T17:40:14Z")\
**Posts on this page:** 3\
**Page:** 2

<div class="post-metadata">

**Author:** ![bakman2](https://sea2.discourse-cdn.com/flex026/user_avatar/discourse.nodered.org/bakman2/32/6207_2.png) [@bakman2](https://discourse.nodered.org/u/bakman2)\
**Post date:** [1 March 2020 09:50 UTC](https://discourse.nodered.org/t/change-an-array-in-a-function/22292/21 "2020-03-01T09:50:30Z")

</div>

Still don't understand what you are trying to achieve...  
You want to modify the service:Database while keeping the order of the array the same (or something) ?

In your map example `obj.active` does not exist. it should be `obj.mactive`  
This works

```auto
a = [{"service": "Check server", "service_status" : false,"paralel":false, "time": null, "st_info":true, "st_debug":false, "mresult":null,"mactive":true},
            {"service": "Database", "service_status" : false,"paralel":true, "time": null,"st_info":true, "st_debug":true,"mresult":null,"mactive":false},
            {"service": "Notificatie", "service_status" : false,"paralel":true, "time": null,"st_info":true, "st_debug":true,"mresult":null,"mactive":true},
            {"service": "OS command", "service_status" : false,"paralel":false, "time": null,"st_info":true, "st_debug":true,"mresult":null,"mactive":false}];

let s = "Database"
let r = null

a.map(obj => {
   if(obj.service === s) { obj.mactive = true;r = obj}
   return obj 
})

node.warn('changed array: '+JSON.stringify(a))

if(r !== null)
    {msg.payload = r;return msg;}

```

---

<div class="post-metadata">

**Author:** ![pvklink](https://avatars.discourse-cdn.com/v4/letter/p/46a35a/32.png) [@pvklink](https://discourse.nodered.org/u/pvklink)\
**Post date:** [1 March 2020 10:17 UTC](https://discourse.nodered.org/t/change-an-array-in-a-function/22292/22 "2020-03-01T10:17:08Z")

</div>

> [@bakman2](#):
>
> Still don't understand what you are trying to achieve...  
> You want to modify the service:Database while keeping the order of the array the same (or something) ?
> 
> In y

Yes, modqueue is an working execution plan, for executing submodules. During the execution, a part of the modules that must be executed can be changed. So i needed a way to update content of that execution plan. Thats updating modqueue.. It works like a charm... And yes i saw the type error mactive/active.. i was playing around with other values.

My original loop version works ok, the new .map version is much shorter and i changed it already...  
So i learned new functionality with this challenge, so thank you all...

jsonata is another thing i never used, so i have to try that too

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/flex026/uploads/nodered/original/1X/d073cd938eafa2e558d7c2cd59003b3ef4963033.png) [@system](https://discourse.nodered.org/u/system)\
**Post date:** [15 March 2020 10:17 UTC](https://discourse.nodered.org/t/change-an-array-in-a-function/22292/23 "2020-03-15T10:17:16Z")

</div>

This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.

[Previous page](https://discourse.nodered.org/t/change-an-array-in-a-function/22292.md?page=1)
