Array & Sets
- More flexible than Objects
-
indexOf
= -1 means the value does not exist in the array. We can useincludes
orsome
(like callback functions). We also haveevery
to review a condition in all elements of the array - map method return an array of the same length, if we want a subset of the array, we can use the method
filter
. But if there is not element matching, we will get an empty array. - Also we can use
reduce
can also be used, but need more arguments. This is the most powerful method for arrays - push to add elements to array, but it will replicate to other arrays with reference (as array is a subtype of objects). We can use
concat
to copy and add values, or use spread operators to clone arrays andslice
-
object.keys()
: allow to generate an array and use the key names - Set don't count equal elements, unless they are in [i], as they will be arrays. We can use this method to find the unique data sets
- Array methods: map(), filter(), reduce(), some()/every(), find()/findeIndex(), forEach(). Plus: slice(), concat(), includes() + spread. Use the best for each case, that makes the code easier to write and follow
Top comments (0)