Skip to content
Related Articles
Open in App
Not now

Related Articles

JavaScript TypeError – Can’t delete non-configurable array element

Improve Article
Save Article
  • Last Updated : 23 Aug, 2020
Improve Article
Save Article

This JavaScript exception can’t delete non-configurable array element that occurs if there is an attempt to short array-length, and any one of the array’s elements is non-configurable.

Message:

TypeError: can't delete non-configurable array element (Firefox)
TypeError: Cannot delete property '2' of [object Array] (Chrome)

Error Type:

TypeError

Cause of error: When one of the array’s elements is non-configurable and code tries to shorten the length of the array.

Example 1: In this example, the array properties are non-configurable and an attempt was made to delete the property by shortening the array length. 

HTML




<script>
    var array = [];
    Object.defineProperty(array, 1, {value: 4}); 
    Object.defineProperty(array, 2, {value: "4"});
    array.length = 1; // Error here
</script>

Output:

TypeError: can't delete non-configurable array element

Example 2: In this example, the array properties are non-configurable and an attempt was made to delete the property by shortening the array length. 

HTML




<script>
    var array = ['a', 'b', 'c'];
    Object.seal(array);
    array.length = 1; // Error here
</script>

Output:

TypeError: can't delete non-configurable array element
My Personal Notes arrow_drop_up
Related Articles

Start Your Coding Journey Now!