Skip to main content

Command Palette

Search for a command to run...

[JavaScript]filter / CallbackFunction /

Updated
•1 min read•View as Markdown
S

👋 Hi there! I'm Suzie, a developer who began my coding journey in 2023. I’m passionate about building fast and dynamic web experiences using Next.js, JavaScript, and Tailwind CSS.

🌱 As I grow in tech, I enjoy documenting my learning journey and sharing insights to help others navigate their path.

✨ Fun fact: When I’m not coding, you can find me practicing Capoeria 🤸.

Let’s connect, learn, and create together!

How to use filter in JavaScript

arrayName.filter((element, index) => element !== arr[index+1];

const arr =[1,1,2,2,3,3];

const answer = arr.filter((x,y) => x !== arr[y+1]);

console.log(answer);

//expacted result : [1,2,3]

x -> value (ex. 1) y -> index (ex. [0])

filter will scan all the elements in the array and filter which is matched with the condition.

JavaScript

Part 1 of 50

JavaScript