puter.kv.add()

Websites Puter Apps Node.js Workers

Add values to an existing key. When you pass an object, each key is treated as a path and the value is added at that path.

Syntax

puter.kv.add(key, value)
puter.kv.add(key, pathAndValue)

Parameters

key (String) (required)

The key to add values to.

value (String | Number | Boolean | Object | Array) (optional)

The value to add to the key.

pathAndValue (Object) (optional)

An object where each key is a dot-separated path (for example, "profile.tags") and each value is the value (or values) to add at that path.

Return value

Returns a Promise that resolves to the updated value stored at key.

Examples

Add values to an array inside an object

<html>
<body>
    <script src="https://js.puter.com/v2/"></script>
    <script>
        (async () => {
            await puter.kv.set('profile', { tags: ['alpha'] });

            const updated = await puter.kv.add('profile', { 'tags': ['beta', 'gamma'] });
            puter.print(`Updated profile: ${JSON.stringify(updated)}`);
        })();
    </script>
</body>
</html>