How does js delete the value of an array element but still occupy the original position?

how does js delete the value of an array element, but still occupy the original position?

Jun.20,2022

non-strict mode can use delete, or directly take the subscript and set the corresponding position value to null or undefined;


then this is not called deletion, it is called replacement. Replace the corresponding position with null or undefined or'


after deleting the value of the array element, its address reference still exists. It's just an empty character.


a = ['one',' two'];
delete a [0];

The result of

/ / a now is: [undefined, 'two'];

a.length = 10;
/ / a now the result is: [undefined, 'two', undefined x 8]

The length of the

array remains the same.


it's not clear whether you're talking about occupying the original position, meaning that the position of the element is retained or the address of the array remains the same.
the previous answer is the first, but the real-world scenario may require the second.
suppose you want to delete the second element, "2"

let a = [1,2, 3] 
a.splice(1,1)

I hope it will help you.

MySQL Query : SELECT * FROM `codeshelper`.`v9_news` WHERE status=99 AND catid='6' ORDER BY rand() LIMIT 5
MySQL Error : Disk full (/tmp/#sql-temptable-64f5-1e52461-66b3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
MySQL Errno : 1021
Message : Disk full (/tmp/#sql-temptable-64f5-1e52461-66b3e.MAI); waiting for someone to free some space... (errno: 28 "No space left on device")
Need Help?