You might get a question check that user with such name exists in the real object.
Obviously, it can be not name or not user.
But the idea is that you need to check a property of the object inside an array.
And actually, there are different ways to implement this.
And the worst way possible is by using for Loop, because as I said previously, full loop is super
low level and it is not as a tool for this specific task.
So let's look how it looks like this for a loop.
So here we want to create the function, for example, is name exists.
And here we must pass two arguments.
First of all, it's a name.
And secondly, it is a ray of our users know inside of a must create a property which will be Boolean,
and it will show us that we have this user inside an array.
So here we can make a let exist, and by default, it will be false.
Now we must try to follow up.
So here we have our left eye from zero and I less than user's length.
And here we make an A-plus plus.
Now what we want to do inside for every single element, we must check its name.
This is why here we are checking the user's I don't name equals our name.
And if it equals, then we want to assign inside to exist through after a for loop.
We want to return our exist property.
So yes, of this code will work.
Let's check this out.
But it is super low level.
As you can see, we have, for example, named John.
Let's right here, John and here comma our users, as you can see, widget and true because we have
such user with such name insiders, Ray, if I am right in here, just full, where get and false.
But the problem with this code, it won't show that you're an advanced developer.
This is why I want to show you three other possibilities to ride this code.
And actually, all these three possibilities are OK.
My favorite will be a single line here so we can create a function is name exists.
And here we get a name and the right.
And as you can see here, I didn't write user's battery because now we can use this function on any
data and know what they want to call.
Here is a red dot sum.
And if you don't know what Sam is doing, you can call some on the ray and given side some predicates
so you want to check something inside.
In our case, Sam will return as true if we have at least one single element which fulfills our condition.
So inside Sam, we can write element and we want to check here element name equals our names that were
passed inside.
And this is literally the same code lake result here, but much smaller.
Let's check the sound I religion page and I'm just type in his name exist as you can see where getting
through.
So actually, Sam is the best solution to this question, but it is also possible to use other solutions.
So let's command the sound and try again.
We have here again two arguments name and array.
Now inside we can try and find element with such name.
This is why here let's create an element and we're using here a red dot.
Find we're getting our element.
And here we want to check element dog name equals zone name from the top.
But in this case, our element is actually an object.
It's not a Boolean.
This is where here must wrap our element in Boolean to return Boolean and not an object.
In this case, it will work correctly.
I'm reloading the page.
As you can see, it is working exactly like this.
So the main difference is that we must try it a little bit more code because we must convert it to Boolean.
And the last thing that we can use here is actually not find but find the index.
And if you don't know what, find the index is doing is exactly the same logic, but were found in the
index of this element.
So if we can find the object with search name inside our array.
So here we're not getting our element button index.
And after this, we know that if this index is less than zero, then this item was not found.
So here we can try to return index bigger than zero.
In this case, even though, OK, it is bigger than zero.
We have this element inside the rape, and as you can see, this code is working exactly the same.
So my approach would be SAM.
The next approach will be find index find is also OK, but you should not use for loop because it is
highly inefficient for such a task.