Hardware FixRecommendedDevice not working? Your driver may be the problemCheck updates for common hardware issues.Fix DriversOctober DealsAmazon USOctober deal check: compare before you payAmazon US: current deals, useful picks and tech finds.Check DealsPC HealthRecommendedCrashes, freezes, slowdowns? Check your PC nowSpot repairable issues before they interrupt work.Check PC×
Skip to content
World desk4 min

JavaScript Functions for CRUD Operations on Objects

Practical JavaScript examples for CRUD operations on in-memory object properties, with clear guidance on computed keys, mutation, and deletion behavior.
Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

JavaScript functions can create, read, update, and delete properties on ordinary objects. These operations change data in memory; they do not, by themselves, save a record to a database or send a request to a server.

What CRUD means for a JavaScript object

An object associates property keys with values. A function stored on an object is commonly called a method, but CRUD helpers can also be ordinary functions that receive an object as an argument. Here, CRUD means creating, reading, updating, and deleting that object’s properties.

As an Amazon Associate I earn from qualifying purchases.

The examples below use a record object and core JavaScript syntax. Bracket notation lets a helper use a property key supplied at runtime; dot notation is convenient when the key is fixed and identifier-like.

What’s actually slowing this PC down?

Pick the symptom - the matching free tool is one click away.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

A small set of CRUD functions

function createRecord(id, value) {
  return { id, value };
}

function readProperty(record, key) {
  return Object.hasOwn(record, key) ? record[key] : undefined;
}

function updateProperty(record, key, value) {
  record[key] = value;
  return record;
}

function deleteProperty(record, key) {
  return delete record[key];
}

const record = createRecord("task-1", "Draft");
readProperty(record, "value");
updateProperty(record, "value", "Published");
deleteProperty(record, "value");

createRecord returns a new object. readProperty checks for an own property before reading it. updateProperty changes the object passed to it, and deleteProperty returns the result of the delete operator.

How to create a property

Create a new object

An object literal is a direct way to create a record-like object: const user = { name: "Mina" };. A function such as createRecord can return a new literal whenever a caller needs a new record.

Add a property to an existing object

Assignment can add a property: user.email = "[email protected]";. Use dot notation for a known identifier-like key. If the key is held in a variable, use brackets: const key = "email"; user[key] = "[email protected]";. Writing user.key would access the literal property named key, not the value stored in the variable.

Assignment to a key that already exists replaces its value. If an operation must create only when a key is absent, it needs an explicit existence check and a defined response for conflicts.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

How to read a property safely

For a fixed key, use record.value; for a computed key, use record[key]. Reading a missing property yields undefined. That result alone cannot tell you whether the property is absent or present with the value undefined.

Object.hasOwn(record, key) checks whether the property belongs directly to the object. This matters when a CRUD helper should operate on the object’s own data rather than values available through its prototype chain. The in operator is not interchangeable: it also reports inherited properties. See MDN’s guide to working with objects.

How updates affect the caller’s object

JavaScript passes an object argument by sharing the object value. Assigning record[key] = value through the parameter changes that same object, so other references to it can observe the change. A helper may return the object for convenient chaining or inspection, as updateProperty does, but the mutation is visible even if the helper returns nothing.

Reassigning the parameter itself is different: function replace(record) { record = {}; } changes only the local parameter binding. It does not make the caller’s variable refer to a new object. For function and parameter behavior, see MDN’s JavaScript functions guide.

Free tools Windows power users keep installed

One-click scans. No signup required.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

Mutate or return a copy?

The example deliberately mutates the passed object. If a caller instead needs a separate shallow object, object spread or Object.assign can make a copy before changing it. A shallow copy has a different identity, while nested objects may still be shared. These approaches therefore have different effects on references; choose according to whether the caller expects the original object to change. MDN documents these object APIs in its Object reference.

Assignments can be constrained

Assignment does not guarantee a successful change in every case. A property may be non-writable, an object may be frozen or non-extensible, or an accessor may define custom behavior. Property descriptors govern attributes such as writability and configurability; consult the MDN Object reference when designing helpers that must handle such objects.

Independent reader supportYour contribution helps us test, update, and keep practical guides available for everyone.Support on Ko-Fi

What delete does—and does not do

delete record[key] attempts to remove an own property. It returns true when deletion succeeds or when the property was absent; it returns false when a non-configurable property cannot be removed in non-strict code. In strict mode, attempting to delete a non-configurable property throws a TypeError.

If an object has an own property that shadows an inherited property, deleting the own property reveals the inherited value; it does not remove the prototype’s property. Deleting a property also is not a direct instruction to free memory. It removes a property reference, while memory management is handled separately. For the operator’s behavior and restrictions, see MDN’s delete reference.

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

In-memory CRUD is not database or API CRUD

Creating or deleting a JavaScript object property changes data in the running program. These language operations do not persist a record after a page or process ends, synchronize changes with a server, or provide database transaction behavior. Saving data or changing a server-side record requires a separate storage or API layer with its own contract.

Product prices and availability are accurate as of the date/time indicated and are subject to change. Any price and availability information displayed on Amazon at the time of purchase will apply.

Leave a Reply

Your email address will not be published. Required fields are marked *

Special offer. See more information about Outbyte and uninstall instructions. Please review EULA and Privacy policy.

More from the Wire

  1. World desk4 min
    How to Spot an AI Voice Scam Before Sending MoneyDon’t rely on how a caller sounds. Pause, call back through a known number, and verify the emergency with another trusted person before sending money.
  2. Mountain View desk4 min
    Google’s SynthID Detector: How to Check AI-Generated Images, Video and AudioGoogle’s SynthID Detector looks for an embedded watermark in supported images, video and audio. Here is what its results do—and do not—show.
  3. Redmond desk20 min
    How to create a link to File or Folder in Windows 11Windows 11 gives you several ways to point to a file or folder without moving or duplicating it. You can create a desktop shortcut,…
Recommended PC Tool
Recommended PC Tool
Windows Errors? Fix Them Before They SpreadFree repair scan
Crashes, No Sound, or Screen Glitches?Free driver scan

Two free Windows tools

One Free Minute Could Fix That PC

Before you go - each of these free tools takes about a minute and tackles what quietly slows a Windows PC down.

Special offer. View Outbyte info, uninstall instructions, EULA, and Privacy Policy.