DEV Community


Posted on

Scrimba's JavaScript Deep Dive - Part IV

Array & Sets

  • More flexible than Objects
  • indexOf= -1 means the value does not exist in the array. We can use includes or some (like callback functions). We also have every 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 and slice
  • 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)

Timeless DEV post...

Git Concepts I Wish I Knew Years Ago

The most used technology by developers is not Javascript.

It's not Python or HTML.

It hardly even gets mentioned in interviews or listed as a pre-requisite for jobs.

I'm talking about Git and version control of course.

One does not simply learn git