What is filter in javascript?

 Array filter method javascript:

 

filter() method returns a new array with filtered all data as given callback function condition if true.

Syntax of filter method:

array.filter(function)

 

filter example in javascript:

 

const colors = ["Red", "blue", "Black", "Red", "Orange", "White"];

 

const getColor = colors.filter(element => element == "Red");

console.log(getColor);

// Array ["Red", "Red"]

 

const getColorNot = colors.filter(element => element == "Green");

console.log(getColorNot);

// Array []

 


No comments:

Note: Only a member of this blog may post a comment.

Copyright Reserved to Anything Learn. Powered by Blogger.