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:



filter example in javascript:


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


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


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


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


// Array []


No comments:

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

Copyright Reserved to Anything Learn. Powered by Blogger.