например, можно так:
<html>
<head>
<title>example</title>
</head>
<body>
<script>
Array.prototype.clear = function ()
{
this.forEach(function (el, b, c)
{
if (el == undefined || el == null)
c.splice(b, 1);
});
}
var myArray = [undefined, 4, 6, 7, -1, null];
myArray.clear();
console.log(myArray);
</script>
</body>
</html>
можно извратиться так: )))
<html>
<head>
<title>example</title>
</head>
<body>
<script>
Array.prototype.clear = function ()
{
this.forEach(function (el, b, c)
{
if (el == undefined || el == null)
c.splice(b, 1);
});
return this;
}
Array.prototype.alert = function ()
{
alert(this.join('; '));
}
var myArray = [undefined, 4, 6, 7, -1, null];
myArray.clear().alert();
</script>
</body>
</html>