Array Function: filter()
It iterates through the array to create a new array. You can
decide which elements should be addded in the new array based on some
conditions.
ES6 is different version of the
ECMAScript specification. Which is the standard that defines the
scripting language that javascript is based on.
ES6 release on 2015 and there are so many features Arrow function,
classes, let and const for variables.
Syntax
arr.filter(item => { // return true/false to add /skip the current item })
Example
Lets see if we return true.
Actually we have used this code in reactjs called as TheArrow.jsx
import React from 'react' function TheFilter() { const myArr = [1, 2, 3, 4]; const myResult = myArr.filter(item => { return true }) console.log(myResult); return ( <div> <h1>Check console</h1> </div> ) } export default TheFilter
Output
Let's take another example of if we return even or odd condition.
import React from 'react' function TheFilter() { const myArr = [1, 2, 3, 4]; const myResult = myArr.filter(item => { return item % 2 === 1; }) console.log(myResult); return ( <div> <h1>Check console</h1> </div> ) } export default TheFilter
Output
if you want you can also check another type of return condition like -
return item % 2 !== 0;
return item % 2 === 0;
Disclaimer
All tutorials are for informational and educational
purposes only and have been made using our own routers, servers, websites and
other vulnerable free resources. we do not contain any illegal activity. We
believe that ethical hacking, information security and cyber security should
be familiar subjects to anyone using digital information and computers.
Hacking Truth is against misuse of the information and we strongly suggest
against it. Please regard the word hacking as ethical hacking or penetration
testing every time this word is used. We do not promote, encourage, support or
excite any illegal activity or hacking.
0 comments:
Post a Comment
For Any Tech Updates, Hacking News, Internet, Computer, Technology and related to IT Field Articles Follow Our Blog.