adam_gataev
5 months agoNew Contributor II
How can I pop the last element from one array and append it to another?
Hello,
I’m working with this JSON structure:
[
{
"field_a": "string",
"entries": [{}, {}, {}],
"shared": []
}
]
I need to remove only the last object from the entries array and append it to the shared array, leaving the other entries intact. What’s the most straightforward way to accomplish this?
Thank you for your help.
Kind regards,
Adam
It’s the newline character in the string that is causing the issue. The dot notation for character matching in regex does not match newlines. After a bit of thought, we can also simplify the result by using the regex group capture syntax. Try this:
$notes.replaceAll('\n','').replace(/.*#IF:(.{9}).*/g, '$1')