Zum Hauptinhalt springen
tsecurity.de LIVE
Echtzeit-Radar & Feeds
Alle RSS Feeds
👥 Community & Social
Sichere ProgrammierungI wanted the diff, not a screenshot: a small URL-change API(24.09.2026 um 06:05 Uhr)
Sichere ProgrammierungFreeze Object Identity Before One Mutator Extract(24.09.2026 um 06:06 Uhr)
Sichere ProgrammierungRun an n8n workflow when a page's text changes(24.09.2026 um 06:12 Uhr)
Sichere ProgrammierungThe Spreadsheet That Runs Your Company (And Why That Should Worry You)(24.09.2026 um 06:12 Uhr)
Sichere ProgrammierungArchitecting an Enterprise Network on AWS Cloud WAN(24.09.2026 um 06:31 Uhr)
Sichere ProgrammierungI wanted the diff, not a screenshot: a small URL-change API(24.09.2026 um 06:05 Uhr)
Sichere ProgrammierungFreeze Object Identity Before One Mutator Extract(24.09.2026 um 06:06 Uhr)
Sichere ProgrammierungRun an n8n workflow when a page's text changes(24.09.2026 um 06:12 Uhr)
Sichere ProgrammierungThe Spreadsheet That Runs Your Company (And Why That Should Worry You)(24.09.2026 um 06:12 Uhr)
Sichere ProgrammierungArchitecting an Enterprise Network on AWS Cloud WAN(24.09.2026 um 06:31 Uhr)
Intelligence View
⚡ tsecurity.de Intelligence

Append object to path - Util function #3

In the past days I've shared with you a few JS utilities, to loop objects recurrently, and also to get data in a nested object or to verify an object path programmatically. In today's utility, you'll get a function to append another…

0
↗ Quelle (dev.to)
Reagiere als Erste:r — dein Feedback zählt!

In the past days I've shared with you a few JS utilities, to loop objects recurrently, and also to get data in a nested object or to verify an object path programmatically.



In today's utility, you'll get a function to append another object inside an object at a specific path.






appendObj(parentObj, childObj, path, cloneParent = false, cloneChild = true)






/**
*
* @param {Object} parentObj the object itself
* @param {string[]} path the sequence to append
* @param {Object} dataTo the data you want to insert
* @returns {Object} the passed object with a the appended object
*/

function appendObj(parentObj, childObj, path, cloneParent = false, cloneChild = true) {
// Verify the parameters
if (getType(parentObj) != "object") throw TypeError("The `parentObj` argument is not an object")
if (getType(childObj) != "object") throw TypeError("The `childObj` argument is not an object")
if (getType(path) != "array") throw TypeError("The `path` argument is not an array")
if (getType(cloneParent) != "boolean") throw TypeError("The `cloneParent` argument is not a boolean")
if (getType(cloneChild) != "boolean") throw TypeError("The `cloneChild` argument is not a boolean")

// clone the child object to avoid shallow copies
if (cloneChild) childObj = structuredClone(childObj)

// If the path is empty assign it at the root
if (path.length == 0) {
Object.assign(parentObj, childObj)
return parentObj;
}

// clone the parent object
if (cloneParent) parentObj = structuredClone(parentObj)

// Link a reference to the parent object
let objRef = parentObj;

// Create path and then assign the object
path.forEach((item, index) => {
if (!Object.keys(objRef).includes(item)) objRef[item] = {}
if (index < path.length - 1) {
objRef = objRef[item]
} else {
if (getType(objRef[item]) != "object") objRef[item] = {}
objRef = objRef[item]
Object.assign(objRef, childObj);
}

});

// return the object
return parentObj;
}

/**
* A method to detect data types more accurately
* Credits: Chris Ferdinandi, https://gomakethings.com/
* @param {*} data the data to be verified
* @returns {String} the data type
*/

export function getType(data) {
return Object.prototype.toString.call(data).toLowerCase().slice(8, -1)
}

/**
* License: MIT, https://opensource.org/license/mit
* Copyright (c) 2024 Rodrigo Isaias Calix
*/











How to use it?



The function requires at least 3 parameters, and 2 optional, in this order:





  • parentObj: This is the main object where you want to append another object


  • childObj: The object you want to append


  • path: a strings array that indicates the path to append the object


  • cloneParent: A boolean that indicates if the parent object you should be cloned or just referenced, default is false.


  • cloneChild: A boolean that indicates if the children object should be cloned or just referenced, default is true.



Usage examples:



With a referenced parent (default)




let products = {
externalDevices: {
keyboard: {
usb: 45,
bluetooth: 25,
}
}
}

const obj = {
mouses: {
usb: 60,
bluetooth: 80
}
}

appendObj(products, obj, ["externalDevices"]);

console.log(products)
/*
{
externalDevices: {
keyboard: {
usb: 45,
bluetooth: 25,
},
mouses: {
usb: 60,
bluetooth: 80
}
}
}
*/








As you can see, you don't need to assign anything to the original object variable, because by default the function uses the original object as a reference and adds to it any data.



With a cloned parent




let copyObj = appendObj(products, obj, ["externalDevices"], true);

console.log(products)
/*
{
externalDevices: {
keyboard: {
usb: 45,
bluetooth: 25,
}
}
}
*/


console.log(copyObj)
/*
{
externalDevices: {
keyboard: {
usb: 45,
bluetooth: 25,
},
mouses: {
usb: 60,
bluetooth: 80
}
}
}
*/







Unlike the previous example, this time the original object doesn't change because it is cloned. You could also, use the products variable to assign it to itself.



Creating an empty object path




appendObj(products, {}, ["externalDevices", "mouses", "bluetooth"]);
console.log(products);

/*
{
externalDevices: {
keyboard: {
usb: 45,
bluetooth: 25,
},
mouses: {
bluetooth: {}
}
}
}
*/











Things you need to know before you use it




  • When cloneParent is set to false the parent object is just referenced, this means that you don't need to assign the object again to the parent, in other words, if you just run the function itself it will automatically add the data to the original object. If it is set to true the function will return a clone of the parent object, but the original object will be unaffected.

  • When clonechildren is set to true it will create a clone of the object and append it. But if you set it to false it will put a shallow copy of it, this means that if the original object has variables in it and the variables change, any reference could reflect that change too, use with caution.

  • If you set the path to an empty array ([]) it will assign the object to the root of the parent object

  • If the path of the object is not defined, it will be created automatically. For example, if in the products object products.devices.audio.microphones "devices" doesn't exist, it will create the path up to "microphones".

  • In the destination of the path, if the destination is an object, the child object will be assigned inside that object along any other data it has, this means that it will override any identical object property inside. If the destination is not an object, it will override the whole value.



If you found this useful, I'll be sharing more content like this on DEV!



You can also find me on X: https://x.com/schemetastic



And remember to save it for later 🔖

SOC Incident Playbook: Remote Code Execution (RCE) Defense
title: Detect Exploitation - Append object to path - Util function #3
id: 1776567a-26ae-4edb-9396-891f05a3250c
status: experimental
description: Automatisch generierte SIEM-Erkennungsregel basierend auf CTI Intelligence
references:
  - https://tsecurity.de/
author: iShareStuff CTI Automated Detection Engine
date: 2026-09-24
logsource:
  category: network_connection
  product: any
detection:
  selection:
      CommandLine|contains:
        - 'exploit'
  condition: selection
falsepositives:
  - Legitime administrative Zugriffe oder Penetrationstests
level: high
tags:
  - attack.initial_access
rule CTI_Threat_Indicator {
    meta:
        author = "iShareStuff CTI Automated Detection Engine"
        date = "2026-09-24"
        description = "YARA Signature for "
    strings:
        $str = "Append object to path - Util f" ascii wide
    condition:
        any of them
}
tsecurity.de Cognitive Threat RAG
Fokus-Vektor:

Kognitive Analyse für identifizierte Bedrohung: Erhöhte Bedrohungslage im Bereich Append object to path - Util function #3.... Basierend auf 368k Vektor-Korrelationen werden sofortige Isolationsmaßnahmen für betroffene Endpunkte empfohlen.

🛡️ Angriffsfläche & Exposure

Netzwerk/Remote-Zugriff ohne Vorauthentifizierung möglich.

Empfohlene Sofortmaßnahmen
  • 1. Perimeter-Inspektion: Relevante Portfreigaben und exponierte Endpunkte unverzüglich scannen.
  • 2. Patch-Applikation: Hersteller-Hotfix einspielen oder betroffene Daemons in isolierte DMZ-Segmente überführen.
  • 3. Telemetrie & EDR-Alerts: Prozessaufrufe und Child-Processes auf anomale Shell-Spawns überwachen.
🔗 Semantisch verwandte Zero-Days MariaDB 11.7 VEC
Ähnliche Beiträge
🔍 Verwandte News

Auch interessante Nachrichten Append object to path - Util function #3

Thematisch verwandte Begriffe: Append, object, path, Util · 6 Treffer

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Laden...

Beiträge werden geladen ...

Laden...

Videos werden geladen ...

Zum Aktualisieren ziehen
ZERO-DAY CVE-2026-96676 | A vulnerability was identified in Fast FAC1900R 20190827_2.0.2. The impa…
Advisory →
TTS Reader • tsecurity.de Voice
tsecurity.de Icon
tsecurity.de App
Offline-Lesen, Eilmeldungen & 0ms Ladezeit

Installiere tsecurity.de direkt auf deinen Home-Bildschirm für das ultimative Vollbild-Magazinerlebnis ohne Browser-Leisten.

Nächster Beitrag
Themen-Radar & Intelligence Matrix
Echtzeit-Taxonomie nach Angriffsvektoren & Plattformen

tsecurity.de Live Threat Radar

🔴 LIVE RADAR
MONITORING
AKTIV
CVE-DATENBANK
LIVE
🔍
Community Radar & Live Chat
Sentinel Bot online • Live-Stream
Dein Cluster: Security Explorer
Match:
lädt…
Verbindung zum Community-Stream wird aufgebaut...
Bearbeitungsmodus — Senden überschreibt deine Nachricht
Community-Puls — was gerade passiert
lädt…
Aktivitäten deiner Analysten
lädt…
Neues Thema oder Eilmeldung einreichen

Reiche interessante Links, Zero-Days oder Debatten ein. Die Community entscheidet per Upvote über die Veröffentlichung.

Heiß diskutierte Einreichungen
🔖 Gespeicherte Artikel
📂 Keine gespeicherten Artikel vorhanden.
Zurück Ziehen Vor
Links: vorheriger Artikel Rechts: nächster Artikel unten: schließen
News NIS-2 Frühwarnung Tier-1 Intel TTP ⏱️ 3 Min vor 10 Min
Artikeldaten werden geladen...

Zurück: vorheriger Vor: nächster
↗ Original-Quelle
Social Reaktionen Deine Reaktion zählt
Einstufung & Relevanz-Poll 0 Stimmen
In sozialen Netzwerken teilen 1-Klick