There are TONS of ways to learn these days, but what’s worked well for me has always been hacking on side projects. , Yarn, ES6… these are a few of the skills I’ve picked up while working on my side project NewClick, an . JavaScript React Etsy advertising platform Today I learned something cool and I thought I’d share it. The ! It’s the tool I’ve always needed…. and it finally came into view. findIndex() method in JavaScript The Problem For my use case, I needed to search through an array of objects and compare two (similar but not matching) objects: As you can see one object has an key/value, while the other does not. Now imagine trying to match these two using one line of code… I’ll spare you a headache, it’s hard to do. What saved my ass in this particular case was using findIndex(). approximate_size Before findIndex() What led me to the method was trying (and ultimately failing) to use it’s younger brother: findIndex() indexOf(). can give you the index of an object in an array, but the objects need to have the EXACT same key/values. If a particular key/value exists in one, but not the other, it won’t work. Which makes sense, seeing as they techincally do not match. indexOf() After findIndex() What I was looking for was a way to match the values of the objects that I KNEW existed in both… This line of code will search our custom audience array and match against the ID, a value that we KNOW exists. The benefit here is that we can use findIndex to match rather than . similar objects exact So there ya go… I learn quite a bit by messing around with side projects and using the latest technology. Yeah, but why? Oh… “but why?”, you ask. So we can filter arrays of course! Oh and also for my react App. I’m building a that allows users to create and save Facebook Audience Targeting Ad Settings. I used the findIndex method to dynamically filter an array of custom audiences, find a match and “check” a checkbox. See a screen shot below! Market research tool Originally published at www.alexdaro.com on August 20, 2018.