Home > Article > Web Front-end > JavaScript uses delete to delete array elements. Usage example [array length remains unchanged]
The example in this article describes the use of JavaScript to delete an array. Share it with everyone for your reference, the details are as follows:
After javascript uses delete to delete certain values in the array, the length of the array remains unchanged.
The specific code is as follows:
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JavaScript delete</title> </head> <body> <script> var a = [1, 2, 3, 4, 5, 6]; for (var i in a) { if (a[i] % 2 == 0) { delete a[i]; } } console.log(a); console.log(a.length); </script> </body> </html>
The running effect diagram is as follows:
I hope this article will be helpful to everyone in JavaScript programming.
For more JavaScript usage examples using delete to delete array elements [the array length remains unchanged], please pay attention to the PHP Chinese website for related articles!