JavaScript Problem: Searching an Array for a Value

  Рет қаралды 38,593

All Things JavaScript, LLC

All Things JavaScript, LLC

Күн бұрын

Пікірлер: 39
@joeyalfaro2323
@joeyalfaro2323 3 жыл бұрын
I got first part but I'm struggling with material lingo and concepts. But I will watch your video until I get it. Great job
@ashrafmagdy926
@ashrafmagdy926 2 жыл бұрын
thanks a lot, this was a smooth explanation of the .find method & the arrow function
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Glad it helped!
@deepuchow
@deepuchow 2 жыл бұрын
Thank you, Sir! you really made me understand this concept. I wasted one entire day understanding by myself.
@AllThingsJavaScript
@AllThingsJavaScript 2 жыл бұрын
Glad it helped!
@andreasdev16
@andreasdev16 6 жыл бұрын
Good one! But if i may ask, what about forEach method? It can also be used to find a certain value inside of an array. Right? It will go through each element inside of an array and return the value that we need.
@AllThingsJavaScript
@AllThingsJavaScript 6 жыл бұрын
Yes, you could use forEach. Some of these methods I presented are easier or provide more information, so I would usually use one of these for searching an array.
@andreasdev16
@andreasdev16 6 жыл бұрын
@@AllThingsJavaScript I see. Thank you!
@peristiloperis7789
@peristiloperis7789 5 жыл бұрын
@@andreasdev16 , forEach can be harmful.
@bonniesitessolutions7728
@bonniesitessolutions7728 2 жыл бұрын
@@peristiloperis7789 How please?
@peristiloperis7789
@peristiloperis7789 2 жыл бұрын
@@bonniesitessolutions7728 hi! to be honest, I can't remember why I wrote that. I was probably wrong.
@huguolin2543
@huguolin2543 5 жыл бұрын
Thanks a lot, the'finIndex' is great. Like you said, 'find' stops as soon as it finds the first match and not the others so a loop is required or can you add a peace of code for it to finish searching the array?
@AllThingsJavaScript
@AllThingsJavaScript 5 жыл бұрын
I believe you would need a loop.
@chris94kennedy
@chris94kennedy 4 жыл бұрын
​@@AllThingsJavaScript You don't need to define a manual loop. You can use .filter( ) on the array to return a new array containing all elements that are equal to a condition you specify. Please see this rough and ready example I wrote: imgur.com/a/IL4xyzZ In this example, you pass an array and a search argument and the function will return a new array containing all the myArray elements that are === to 7. You can use this in much more complicated use cases, and in conjunction with methods like .includes( ), for searching through large arrays of objects returned by an API for example. .includes( ) is incredibly useful since you won't require a user to enter a search-term that is === to the property you are matching against, e.g. if a user is searching for a string "remember to feed the neighbour's cat", .includes( ) does not require the user to enter the precise search term. They could just write neighbour :)
@leonardofalcoski8575
@leonardofalcoski8575 3 жыл бұрын
@@chris94kennedy Thank you so much, man. You helped me a lot.
@chris94kennedy
@chris94kennedy 3 жыл бұрын
@@leonardofalcoski8575 youre welcome, glad it helped
@rickyu1978
@rickyu1978 6 жыл бұрын
Concise and to the point! Do you have a video on comparison of two arrays, finding duplicates, removing them and concatenating them? I am trying to loop over a array that splices itself (poping off duplicate value), obviously this doesnt work. Is it okay to mutate a array or create a new array due to "immutability programming styles"
@AllThingsJavaScript
@AllThingsJavaScript 6 жыл бұрын
You may want to convert the Array to a Set in order to do what you are trying. Here is a tutorial on Sets: kzbin.info/www/bejne/eWmlgqyvqM-Fg6c Also, I think I will use this topic for a tutorial in the future. As to the question of mutating an array, some would say no it is not OK to do that. Especially those that follow a functional paradigm. A lean towards that philosophy, but also feel there are times when it is OK to mutate.
@rickyu1978
@rickyu1978 6 жыл бұрын
Hi, I have tried using sets, but the issue with sets is that it doesn't work with nested objects within a array, thus each object within a array is considered unique. I guess i am looking for a filter or .map that could work with 2 arrays and find duplicates and spit out a new array perhaps. Thanks for your input , i might take up your advanced JS course if it covers these topics.
@AllThingsJavaScript
@AllThingsJavaScript 6 жыл бұрын
Actually the issue is testing objects. variable that reference objects are only equal to one another if they reference the same object. Two objects that look exactly the same to you and I are not equal. This is a part of the object discussion in my advanced course.
@filiplahoda248
@filiplahoda248 5 жыл бұрын
I am bit confused, you say that when using the function in the find method we will return true or false, but then the value is returned. What role does true or false play in that process?
@AllThingsJavaScript
@AllThingsJavaScript 5 жыл бұрын
If the condition is true, the value is returned. Does that help?
@quocthinhhuynh2134
@quocthinhhuynh2134 4 жыл бұрын
when the find() method meets a true, it stops and returns the value of where it stops
@priyankasurve7009
@priyankasurve7009 5 жыл бұрын
How to compare in lowercase array of string using indexof
@AllThingsJavaScript
@AllThingsJavaScript 5 жыл бұрын
Can you give me an example of what you are trying to accomplish?
@chris94kennedy
@chris94kennedy 4 жыл бұрын
use .toLowerCase()
@sebastiankumlin9542
@sebastiankumlin9542 6 жыл бұрын
Good explanation
@sauravuppoor
@sauravuppoor 6 жыл бұрын
Thanks a lot for this video. Helped a lot. 😊
@emmtzi1
@emmtzi1 6 жыл бұрын
Very good explanation!
@Michael-fl9lh
@Michael-fl9lh 4 жыл бұрын
Which one is the fastest way to search in an array with more than twenty thousand elements?
@AllThingsJavaScript
@AllThingsJavaScript 4 жыл бұрын
I haven't tested this myself, but I believe indexOf would be faster for large arrays. I will have to test it.
@rajeshnaika7354
@rajeshnaika7354 6 жыл бұрын
I love your videos. do you have angular videos of yours in udemy, if yes how much the fee, let me know, please.
@AllThingsJavaScript
@AllThingsJavaScript 6 жыл бұрын
I haven't done any angular videos yet.
@RyanM-gc4og
@RyanM-gc4og 6 жыл бұрын
well done. clear explanation. purchased both of your js courses on udemy after watching this. thanks.
@AllThingsJavaScript
@AllThingsJavaScript 6 жыл бұрын
Thanks for the support!
@danisgadkari8053
@danisgadkari8053 4 жыл бұрын
Thanks bro !
@miqbal7032
@miqbal7032 2 жыл бұрын
JavaScript for get data in table from localStorage
@seenuvasanv
@seenuvasanv 7 жыл бұрын
Thanks
@forestbugg755
@forestbugg755 3 жыл бұрын
Superb
Getting Comfortable with the ES5 Array Methods in JavaScript
30:56
All Things JavaScript, LLC
Рет қаралды 6 М.
JavaScript Tip: 7 Ways to Iterate Over an Array
15:11
All Things JavaScript, LLC
Рет қаралды 9 М.
小丑女COCO的审判。#天使 #小丑 #超人不会飞
00:53
超人不会飞
Рет қаралды 16 МЛН
99.9% IMPOSSIBLE
00:24
STORROR
Рет қаралды 31 МЛН
Quando eu quero Sushi (sem desperdiçar) 🍣
00:26
Los Wagners
Рет қаралды 15 МЛН
Search from array of objects in javascript
21:11
Hitesh Choudhary
Рет қаралды 129 М.
JavaScript Problem: Extracting Numbers from a String
15:17
All Things JavaScript, LLC
Рет қаралды 9 М.
Higher Order Functions: A JavaScript Strong Point
8:15
All Things JavaScript, LLC
Рет қаралды 26 М.
JavaScript Problem: Combining and Sorting Objects in an Array
21:39
All Things JavaScript, LLC
Рет қаралды 4,8 М.
Using split to Manipulate a JavaScript String
12:57
All Things JavaScript, LLC
Рет қаралды 8 М.
Understanding JavaScript Callbacks
15:39
All Things JavaScript, LLC
Рет қаралды 115 М.
Converting a JavaScript String to an Array
7:16
All Things JavaScript, LLC
Рет қаралды 17 М.
The Ins and Outs of localStorage and sessionStorage
16:13
All Things JavaScript, LLC
Рет қаралды 5 М.
JavaScript Higher Order Functions & Arrays
34:56
Traversy Media
Рет қаралды 990 М.
8 Must Know JavaScript Array Methods
10:05
Web Dev Simplified
Рет қаралды 1 МЛН