Delete Operator - JavaScript - MDN Web Docs - Mozilla
- Skip to main content
- Skip to search
This feature is well established and works across many devices and browser versions. It’s been available across browsers since July 2015.
- Learn more
- See full compatibility
- Report feedback
The delete operator removes a property from an object. If the property's value is an object and there are no more references to the object, the object held by that property is eventually released automatically.
In this article
- Try it
- Syntax
- Description
- Examples
- Specifications
- Browser compatibility
- See also
Try it
const employee = { firstName: "Maria", lastName: "Sanchez", }; console.log(employee.firstName); // Expected output: "Maria" delete employee.firstName; console.log(employee.firstName); // Expected output: undefinedSyntax
jsdelete object.property delete object[property]Note: The syntax allows a wider range of expressions following the delete operator, but only the above forms lead to meaningful behaviors.
Parameters
objectThe name of an object, or an expression evaluating to an object.
propertyThe property to delete.
Return value
true for all cases except when the property is an own non-configurable property, in which case false is returned in non-strict mode.
Exceptions
TypeErrorThrown in strict mode if the property is an own non-configurable property.
ReferenceErrorThrown if object is super.
Description
The delete operator has the same precedence as other unary operators like typeof. Therefore, it accepts any expression formed by higher-precedence operators. However, the following forms lead to early syntax errors in strict mode:
jsdelete identifier; delete object.#privateProperty;Because classes are automatically in strict mode, and private elements can only be legally referenced in class bodies, this means private elements can never be deleted. While delete identifier may work if identifier refers to a configurable property of the global object, you should avoid this form and prefix it with globalThis instead.
While other expressions are accepted, they don't lead to meaningful behaviors:
jsdelete console.log(1); // Logs 1, returns true, but nothing deletedThe delete operator removes a given property from an object. On successful deletion, it will return true, else false will be returned. Unlike what common belief suggests (perhaps due to other programming languages like delete in C++), the delete operator has nothing to do with directly freeing memory. Memory management is done indirectly via breaking references. See the memory management page for more details.
It is important to consider the following scenarios:
- If the property which you are trying to delete does not exist, delete will not have any effect and will return true.
- delete only has an effect on own properties. If a property with the same name exists on the object's prototype chain, then after deletion, the object will use the property from the prototype chain.
- Non-configurable properties cannot be removed. This includes properties of built-in objects like Math, Array, Object and properties that are created as non-configurable with methods like Object.defineProperty().
- Deleting variables, including function parameters, never works. delete variable will throw a SyntaxError in strict mode, and will have no effect in non-strict mode.
- Any variable declared with var cannot be deleted from the global scope or from a function's scope, because while they may be attached to the global object, they are not configurable.
- Any variable declared with let or const cannot be deleted from the scope within which they were defined, because they are not attached to an object.
Examples
Using delete
Note: The following example uses non-strict-mode only features, like implicitly creating global variables and deleting identifiers, which are forbidden in strict mode.
js// Creates the property empCount on the global scope. // Since we are using var, this is marked as non-configurable. var empCount = 43; // Creates the property EmployeeDetails on the global scope. // Since it was defined without "var", it is marked configurable. EmployeeDetails = { name: "xyz", age: 5, designation: "Developer", }; // delete can be used to remove properties from objects. delete EmployeeDetails.name; // returns true // Even when the property does not exist, delete returns "true". delete EmployeeDetails.salary; // returns true // EmployeeDetails is a property of the global scope. delete EmployeeDetails; // returns true // On the contrary, empCount is not configurable // since var was used. delete empCount; // returns false // delete also does not affect built-in static properties // that are non-configurable. delete Math.PI; // returns false function f() { var z = 44; // delete doesn't affect local variable names delete z; // returns false }delete and the prototype chain
In the following example, we delete an own property of an object while a property with the same name is available on the prototype chain:
jsfunction Foo() { this.bar = 10; } Foo.prototype.bar = 42; const foo = new Foo(); // foo.bar is associated with the // own property. console.log(foo.bar); // 10 // Delete the own property within the // foo object. delete foo.bar; // returns true // foo.bar is still available in the // prototype chain. console.log(foo.bar); // 42 // Delete the property on the prototype. delete Foo.prototype.bar; // returns true // The "bar" property can no longer be // inherited from Foo since it has been // deleted. console.log(foo.bar); // undefinedDeleting array elements
When you delete an array element, the array length is not affected. This holds even if you delete the last element of the array.
When the delete operator removes an array element, that element is no longer in the array. In the following example, trees[3] is removed with delete.
jsconst trees = ["redwood", "bay", "cedar", "oak", "maple"]; delete trees[3]; console.log(3 in trees); // falseThis creates a sparse array with an empty slot. If you want an array element to exist but have an undefined value, use the undefined value instead of the delete operator. In the following example, trees[3] is assigned the value undefined, but the array element still exists:
jsconst trees = ["redwood", "bay", "cedar", "oak", "maple"]; trees[3] = undefined; console.log(3 in trees); // trueIf instead, you want to remove an array element by changing the contents of the array, use the splice() method. In the following example, trees[3] is removed from the array completely using splice():
jsconst trees = ["redwood", "bay", "cedar", "oak", "maple"]; trees.splice(3, 1); console.log(trees); // ["redwood", "bay", "cedar", "maple"]Deleting non-configurable properties
When a property is marked as non-configurable, delete won't have any effect, and will return false. In strict mode, this will raise a TypeError.
jsconst Employee = {}; Object.defineProperty(Employee, "name", { configurable: false }); console.log(delete Employee.name); // returns falsevar creates non-configurable properties that cannot be deleted with the delete operator:
js// Since "nameOther" is added using with the // var keyword, it is marked as non-configurable var nameOther = "XYZ"; // We can access this global property using: Object.getOwnPropertyDescriptor(globalThis, "nameOther"); // { // value: "XYZ", // writable: true, // enumerable: true, // configurable: false // } delete globalThis.nameOther; // return falseIn strict mode, this would raise an exception.
Deleting global properties
If a global property is configurable (for example, via direct property assignment), it can be deleted, and subsequent references to them as global variables will produce a ReferenceError.
jsglobalThis.globalVar = 1; console.log(globalVar); // 1 // In non-strict mode, you can use `delete globalVar` as well delete globalThis.globalVar; console.log(globalVar); // ReferenceError: globalVar is not definedSpecifications
| Specification |
|---|
| ECMAScript® 2026 Language Specification# sec-delete-operator |
Browser compatibility
See also
- Reflect.deleteProperty()
- Map.prototype.delete()
Help improve MDN
Was this page helpful to you? Yes No Learn how to contributeThis page was last modified on Jul 17, 2025 by MDN contributors.
View this page on GitHub • Report a problem with this content Filter sidebar- JavaScript
- Tutorials and guides
- JavaScript Guide
- Introduction
- Grammar and types
- Control flow and error handling
- Loops and iteration
- Functions
- Expressions and operators
- Numbers and strings
- Representing dates & times
- Regular expressions
- Indexed collections
- Keyed collections
- Working with objects
- Using classes
- Using promises
- JavaScript typed arrays
- Iterators and generators
- Resource management
- Internationalization
- JavaScript modules
- Intermediate
- Language overview
- JavaScript data structures
- Equality comparisons and sameness
- Enumerability and ownership of properties
- Closures
- Advanced
- Inheritance and the prototype chain
- Meta programming
- Memory Management
- References
- Built-in objects
- AggregateError
- Array
- ArrayBuffer
- AsyncDisposableStack
- AsyncFunction
- AsyncGenerator
- AsyncGeneratorFunction
- AsyncIterator
- Atomics
- BigInt
- BigInt64Array
- BigUint64Array
- Boolean
- DataView
- Date
- decodeURI()
- decodeURIComponent()
- DisposableStack
- encodeURI()
- encodeURIComponent()
- Error
- escape() Deprecated
- eval()
- EvalError
- FinalizationRegistry
- Float16Array
- Float32Array
- Float64Array
- Function
- Generator
- GeneratorFunction
- globalThis
- Infinity
- Int8Array
- Int16Array
- Int32Array
- InternalError Non-standard
- Intl
- isFinite()
- isNaN()
- Iterator
- JSON
- Map
- Math
- NaN
- Number
- Object
- parseFloat()
- parseInt()
- Promise
- Proxy
- RangeError
- ReferenceError
- Reflect
- RegExp
- Set
- SharedArrayBuffer
- String
- SuppressedError
- Symbol
- SyntaxError
- Temporal
- TypedArray
- TypeError
- Uint8Array
- Uint8ClampedArray
- Uint16Array
- Uint32Array
- undefined
- unescape() Deprecated
- URIError
- WeakMap
- WeakRef
- WeakSet
- Expressions & operators
- Addition (+)
- Addition assignment (+=)
- Assignment (=)
- async function expression
- async function* expression
- await
- Bitwise AND (&)
- Bitwise AND assignment (&=)
- Bitwise NOT (~)
- Bitwise OR (|)
- Bitwise OR assignment (|=)
- Bitwise XOR (^)
- Bitwise XOR assignment (^=)
- class expression
- Comma operator (,)
- Conditional (ternary) operator
- Decrement (--)
- delete
- Destructuring
- Division (/)
- Division assignment (/=)
- Equality (==)
- Exponentiation (**)
- Exponentiation assignment (**=)
- function expression
- function* expression
- Greater than (>)
- Greater than or equal (>=)
- Grouping operator ( )
- import.meta
- import.meta.resolve()
- import()
- in
- Increment (++)
- Inequality (!=)
- instanceof
- Left shift (<<)
- Left shift assignment (<<=)
- Less than (<)
- Less than or equal (<=)
- Logical AND (&&)
- Logical AND assignment (&&=)
- Logical NOT (!)
- Logical OR (||)
- Logical OR assignment (||=)
- Multiplication (*)
- Multiplication assignment (*=)
- new
- new.target
- null
- Nullish coalescing assignment (??=)
- Nullish coalescing operator (??)
- Object initializer
- Operator precedence
- Optional chaining (?.)
- Property accessors
- Remainder (%)
- Remainder assignment (%=)
- Right shift (>>)
- Right shift assignment (>>=)
- Spread syntax (...)
- Strict equality (===)
- Strict inequality (!==)
- Subtraction (-)
- Subtraction assignment (-=)
- super
- this
- typeof
- Unary negation (-)
- Unary plus (+)
- Unsigned right shift (>>>)
- Unsigned right shift assignment (>>>=)
- void operator
- yield
- yield*
- Statements & declarations
- async function
- async function*
- await using
- Block statement
- break
- class
- const
- continue
- debugger
- do...while
- Empty statement
- export
- Expression statement
- for
- for await...of
- for...in
- for...of
- function
- function*
- if...else
- import
- Import attributes
- Labeled statement
- let
- return
- switch
- throw
- try...catch
- using
- var
- while
- with Deprecated
- Functions
- Arrow function expressions
- Default parameters
- get
- Method definitions
- Rest parameters
- set
- The arguments object
- [Symbol.iterator]()
- callee Deprecated
- length
- Classes
- constructor
- extends
- Private elements
- Public class fields
- static
- Static initialization blocks
- Regular expressions
- Backreference: \1, \2
- Capturing group: (...)
- Character class escape: \d, \D, \w, \W, \s, \S
- Character class: [...], [^...]
- Character escape: \n, \u{...}
- Disjunction: |
- Input boundary assertion: ^, $
- Literal character: a, b
- Lookahead assertion: (?=...), (?!...)
- Lookbehind assertion: (?<=...), (?<!...)
- Modifier: (?ims-ims:...)
- Named backreference: \k<name>
- Named capturing group: (?<name>...)
- Non-capturing group: (?:...)
- Quantifier: *, +, ?, {n}, {n,}, {n,m}
- Unicode character class escape: \p{...}, \P{...}
- Wildcard: .
- Word boundary assertion: \b, \B
- Errors
- AggregateError: No Promise in Promise.any was resolved
- Error: Permission denied to access property "x"
- InternalError: too much recursion
- RangeError: argument is not a valid code point
- RangeError: BigInt division by zero
- RangeError: BigInt negative exponent
- RangeError: form must be one of 'NFC', 'NFD', 'NFKC', or 'NFKD'
- RangeError: invalid array length
- RangeError: invalid date
- RangeError: precision is out of range
- RangeError: radix must be an integer
- RangeError: repeat count must be less than infinity
- RangeError: repeat count must be non-negative
- RangeError: x can't be converted to BigInt because it isn't an integer
- ReferenceError: "x" is not defined
- ReferenceError: assignment to undeclared variable "x"
- ReferenceError: can't access lexical declaration 'X' before initialization
- ReferenceError: must call super constructor before using 'this' in derived class constructor
- ReferenceError: super() called twice in derived class constructor
- SyntaxError: 'arguments'/'eval' can't be defined or assigned to in strict mode code
- SyntaxError: "0"-prefixed octal literals are deprecated
- SyntaxError: "use strict" not allowed in function with non-simple parameters
- SyntaxError: "x" is a reserved identifier
- SyntaxError: \ at end of pattern
- SyntaxError: a declaration in the head of a for-of loop can't have an initializer
- SyntaxError: applying the 'delete' operator to an unqualified name is deprecated
- SyntaxError: arguments is not valid in fields
- SyntaxError: await is only valid in async functions, async generators and modules
- SyntaxError: await/yield expression can't be used in parameter
- SyntaxError: cannot use `??` unparenthesized within `||` and `&&` expressions
- SyntaxError: character class escape cannot be used in class range in regular expression
- SyntaxError: continue must be inside loop
- SyntaxError: duplicate capture group name in regular expression
- SyntaxError: duplicate formal argument x
- SyntaxError: for-in loop head declarations may not have initializers
- SyntaxError: function statement requires a name
- SyntaxError: functions cannot be labelled
- SyntaxError: getter and setter for private name #x should either be both static or non-static
- SyntaxError: getter functions must have no arguments
- SyntaxError: identifier starts immediately after numeric literal
- SyntaxError: illegal character
- SyntaxError: import declarations may only appear at top level of a module
- SyntaxError: incomplete quantifier in regular expression
- SyntaxError: invalid assignment left-hand side
- SyntaxError: invalid BigInt syntax
- SyntaxError: invalid capture group name in regular expression
- SyntaxError: invalid character in class in regular expression
- SyntaxError: invalid class set operation in regular expression
- SyntaxError: invalid decimal escape in regular expression
- SyntaxError: invalid identity escape in regular expression
- SyntaxError: invalid named capture reference in regular expression
- SyntaxError: invalid property name in regular expression
- SyntaxError: invalid range in character class
- SyntaxError: invalid regexp group
- SyntaxError: invalid regular expression flag "x"
- SyntaxError: invalid unicode escape in regular expression
- SyntaxError: JSON.parse: bad parsing
- SyntaxError: label not found
- SyntaxError: missing : after property id
- SyntaxError: missing ) after argument list
- SyntaxError: missing ) after condition
- SyntaxError: missing ] after element list
- SyntaxError: missing } after function body
- SyntaxError: missing } after property list
- SyntaxError: missing = in const declaration
- SyntaxError: missing formal parameter
- SyntaxError: missing name after . operator
- SyntaxError: missing variable name
- SyntaxError: negated character class with strings in regular expression
- SyntaxError: new keyword cannot be used with an optional chain
- SyntaxError: nothing to repeat
- SyntaxError: numbers out of order in {} quantifier.
- SyntaxError: octal escape sequences can't be used in untagged template literals or in strict mode code
- SyntaxError: parameter after rest parameter
- SyntaxError: private fields can't be deleted
- SyntaxError: property name __proto__ appears more than once in object literal
- SyntaxError: raw bracket is not allowed in regular expression with unicode flag
- SyntaxError: redeclaration of formal parameter "x"
- SyntaxError: reference to undeclared private field or method #x
- SyntaxError: rest parameter may not have a default
- SyntaxError: return not in function
- SyntaxError: setter functions must have one argument
- SyntaxError: string literal contains an unescaped line break
- SyntaxError: super() is only valid in derived class constructors
- SyntaxError: tagged template cannot be used with optional chain
- SyntaxError: Unexpected '#' used outside of class body
- SyntaxError: Unexpected token
- SyntaxError: unlabeled break must be inside loop or switch
- SyntaxError: unparenthesized unary expression can't appear on the left-hand side of '**'
- SyntaxError: use of super property/member accesses only valid within methods or eval code within methods
- SyntaxError: Using //@ to indicate sourceURL pragmas is deprecated. Use //# instead
- TypeError: 'caller', 'callee', and 'arguments' properties may not be accessed
- TypeError: 'x' is not iterable
- TypeError: "x" is (not) "y"
- TypeError: "x" is not a constructor
- TypeError: "x" is not a function
- TypeError: "x" is not a non-null object
- TypeError: "x" is read-only
- TypeError: already executing generator
- TypeError: BigInt value can't be serialized in JSON
- TypeError: calling a builtin X constructor without new is forbidden
- TypeError: can't access/set private field or method: object is not the right class
- TypeError: can't assign to property "x" on "y": not an object
- TypeError: can't convert BigInt to number
- TypeError: can't convert x to BigInt
- TypeError: can't define property "x": "obj" is not extensible
- TypeError: can't delete non-configurable array element
- TypeError: can't redefine non-configurable property "x"
- TypeError: can't set prototype of this object
- TypeError: can't set prototype: it would cause a prototype chain cycle
- TypeError: cannot use 'in' operator to search for 'x' in 'y'
- TypeError: class constructors must be invoked with 'new'
- TypeError: cyclic object value
- TypeError: derived class constructor returned invalid value x
- TypeError: getting private setter-only property
- TypeError: Initializing an object twice is an error with private fields/methods
- TypeError: invalid 'instanceof' operand 'x'
- TypeError: invalid Array.prototype.sort argument
- TypeError: invalid assignment to const "x"
- TypeError: Iterator/AsyncIterator constructor can't be used directly
- TypeError: matchAll/replaceAll must be called with a global RegExp
- TypeError: More arguments needed
- TypeError: null/undefined has no properties
- TypeError: property "x" is non-configurable and can't be deleted
- TypeError: Reduce of empty array with no initial value
- TypeError: setting getter-only property "x"
- TypeError: WeakSet key/WeakMap value 'x' must be an object or an unregistered symbol
- TypeError: X.prototype.y called on incompatible type
- URIError: malformed URI sequence
- Warning: -file- is being assigned a //# sourceMappingURL, but already has one
- Warning: unreachable code after return statement
- Misc
- JavaScript technologies overview
- Execution model
- Lexical grammar
- Iteration protocols
- Strict mode
- Template literals
- Trailing commas
- Deprecated features
Từ khóa » Xóa Object Trong Mảng Javascript
-
Xóa Phần Tử Trong Array JavaScript - Viblo
-
Xóa Phần Tử Trong Mảng JavaScript(shift, Pop, Splice)
-
9+ Cách để Xóa Một Phần Tử Ra Khỏi JavaScript Array | TopDev
-
Một Số Cách để Xóa Phần Tử Khỏi Mảng Javascript - Homiedev
-
Javascript Tips: Cách Xóa Phần Tử Ra Khỏi Mảng - Freetuts
-
Cách Xóa Một Mục Khỏi Mảng Trong JavaScript - Tech Wiki
-
Xóa Phần Tử Trong Mảng Javascript? - Tạo Website
-
Làm Cách Nào để Xóa Các đối Tượng Khỏi Mảng Kết Hợp Javascript?
-
Các Phương Thức Của Mảng Trong Javascript - KungFu Tech
-
9+ Cách Để Xóa Phần Tử Trong Object Javascript ? Javascript Tips
-
9+ Cách Để Xóa Phần Tử Trong Object Javascript ? Javascript Tips ...
-
9+ Cách Để Xóa Phần Tử Trong Object Javascript ? Javascript Tips
-
Shift() - Xóa Phần Tử đầu Tiên Của Mảng Trong JavaScript - Web Cơ Bản
-
JavaScript Array Và Object, Khái Niệm Và Cách Dùng - ThucHa.Info