Home  >  Article  >  Web Front-end  >  JavaScript uses delete to delete array elements. Usage example [array length remains unchanged]

JavaScript uses delete to delete array elements. Usage example [array length remains unchanged]

高洛峰
高洛峰Original
2017-01-20 11:08:592068browse

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:

JavaScript uses delete to delete array elements. Usage example [array length remains unchanged]

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!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn