Home > Web Front-end > JS Tutorial > body text

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

高洛峰
Release: 2017-01-20 11:08:59
Original
2067 people have browsed it

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>
Copy after login

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!