ES5 find() Method in JavaScript

JavaScript
Transcript

English (Auto-generated)

in previous podcasts, we talked about, we talked about the find and the some. Sorry, we talked about the some and every method and in this code cast, we're going to be talking about the find array method. So what does the find ray method do? So the find method is going to return the first occurrence of a query value within an array. So picking up from the previous code cast and we where we use the hackathon team array, which is an array with four objects and each object has a name, roll and enrolled a property value. So let's use the find method here to check if any of the roles in the hackathon team are, you know, a designer. So we're checking specifically for if any person in our hackathon team is a designer. Now this method is not going to to mutate the original array. So we will declare a new variable called lead designer is equal to use the find method on the hackathon Timorese. So hackathon got team find method and this takes as an argument. The method takes as an argument, a callback function which is going to be executed for each item in the array. So it's going to be executed for each object in the array. And what we're checking to see is if any of the objects role property is strictly equal to the strength designer. Right? So let's go ahead and check this out. And I already have uh this commented. So I'm going to uncommon. Nted but basically it's an if else block. And if a designer. So yes, if we found a designer, then we wanted to basically insert something in the inner html of the body in this document. And we're going to say designer is And then I am going to use out here a template string and I'm basically going to return the designer. And if there is no designer found, then I'll say, well, you know, no designer found. So let's go ahead and comment this out and use control S to see what we get. So think designer is object object because out here we have to use the Jason dot string if I method to basically pass this object and uh that are think which we will be inserting into the dom and there you go. So now it lets us know. Yes, we found a designer. And this is the designer that we found in our team. Now since the find method is returning the first occurrence of a query value that it finds. We can actually maybe change um the, you know, the front end rule. So change this value from front end to be designer. And then control. S. And now we see that it returned to us the first occurrence that it found of the role property whose value is the string designer. Mhm. So that's all about the find method
257 Views 0 Likes 0 Comments

Let's talk about the find() method in JavaScript which returns the first occurrence of a queried value

Comment
Leave a comment (supports markdown format)