from Array Method | JavaScript Tutorial

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
the array from method creates a new shallow copied array from an array like or iterable object now this sounds a bit confusing so let's look at some examples on how this works exactly let's say we want to convert a string of numbers to an array of numbers so let's say we have string of 1 2 3 4 5 6 7 something like that and at the end we want to get something like 1 2 3 4 5 6 7 how we can do that well one option is to use the array from method let's store the result in a rest variable and we're going to do array not from string and let's see what we get comes for the flaw grass you can see now that we have an array of characters which are the numbers so how can we convert three numbers to actual numbers we can do that by passing map function as the second parameter for the array from method here we can pass the map function let's write map function here and create it here function math function which will take in the value so this works exactly as the map function we learned in the previous tutorial so let's say X and we want to return number of X so we're going over all the elements from this array and you want to convert them to numbers let's save and see we get now an array of numbers which is great but we can go even further we can convert this to an arrow functions so we get X and we want to return number X like this so this is the same thing say then is the same or we can just pass in the numbers constructor and we get the same thing which is great now another use case for this array from method is if you want to remove all the duplicated values from an array so let's write first let's console and clear this so we have a clean terminal alright and now let's create a numbers array and let's see we have one two three three two one four four one three okay something like that get and let's have a five and we want to remove the duplicated values so for that we're going to create a new set which will remove all the duplicates and then we need to convert that set to an array again so let's store this in a result we're going to call new set and we're going to pass in the numbers let's see what we get now okay we have a new set with all the numbers but this is not an array so we can use the array dot from and pass in the new set and now if we save you can see we get all the numbers and we remove the duplicate this can work for Strings also something like Britney van Liam terrine again run again and J maybe let's call these friends okay and now you can see we get an array of friends with all the duplicate friends three moved all right I hope you enjoyed this tutorial and I see in the next one bye [Music]
Info
Channel: Florin Pop
Views: 3,690
Rating: 4.8865247 out of 5
Keywords: javascript, javascript tutorial, javascript tutorial for beginners, array method, javascript arrays, learn javascript, javascript array methods, learn map, array from, from array, from array method, learn array from, remove duplicates from an array, javascript array from, set
Id: qS79OIceQ7k
Channel Id: undefined
Length: 4min 4sec (244 seconds)
Published: Fri Apr 03 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.