Hello!
I’m using the following code to get item wise list of queries.
const serialItems = [];
for (const element of items[0].json) {
serialItems.push({json: element});
}
return serialItems;
Is there a way to find and replace some strings in the values of a specific key?
Here’s my small workflow:
mock data and workflow
Is it possible to remove “+” and “-” in “COUNT” key for all the items at the time of running the 2nd node itself?
Any pointers are highly appreciated.
Use the code below in the function node.
const serialItems = [];
for (const element of items[0].json) {
serialItems.push({json: { COUNT: element.COUNT.replace('+', '').replace('-', '') }});
}
return serialItems;
1 Like
Thank you @RicardoE105!
However, this code removes all keys but “COUNT” from the query. How can I prevent it?
I do not get it. Can you share the output as you want it exactly?
I just realized that I missed out the “key” from my mock data. This is what the output should be:
[
{
"COUNT": "11",
"key":"value"
},
{
"COUNT": "21",
"key":"value2"
},
{
"COUNT": "31",
"key":"value3"
}
]
This is what I get:
[
{
"COUNT": "11"
},
{
"COUNT": "21"
},
{
"COUNT": "31"
}
]
const serialItems = [];
for (const element of items[0].json) {
serialItems.push({json: { ...element, COUNT: element.COUNT.replace('+', '').replace('-', '') }});
}
return serialItems;
1 Like