How to use filter() function In Javascript

This method is used to create a new array from a given array consisting of only those elements from the given array which satisfy a condition set by the argument function. 

Example:

Javascript
// JavaScript to illustrate filter() method
function isPositive(value) {
    return value > 0;
}

function func() {
    let filtered = [101, 98, 12, -1, 848].filter(isPositive);
    console.log("Positive elements in array: " + filtered);
}
func();

Output
Positive elements in array: 101,98,12,848

How to remove an element from an array in JavaScript?

Removing elements from an array is a fundamental operation in JavaScript, essential for data manipulation, filtering, and transformation. This guide will explore different methods to efficiently remove elements from an array, enhancing your understanding and capability in handling arrays.

Similar Reads

Why Remove Elements from an Array?

Removing elements from an array is important for:...

1. Using pop method

pop() method is used to remove the last element of the array and returns the removed element. This function decreases the length of the array by 1....

2. Using shift method

shift() method is used to remove the first element of the array and reduce the size of the original array by 1....

3. Using splice method

The JavaScript Array splice() method can be used to remove any particular element from an array in JavaScript. Moreover, this function can be used to add/remove more than one element from an array....

4. Using filter() function

This method is used to create a new array from a given array consisting of only those elements from the given array which satisfy a condition set by the argument function....

5. Using Delete Operator

Use the Delete Operator to remove elements from a JavaScript array....

6. UsingĀ _.remove() method

TheĀ _.remove() methodĀ is used to remove all elements from the array that predicate returns True and returns the removed elements....