Created
August 18, 2022 06:55
-
-
Save ahamed/313a0f7cf527ffbbb8b015094ee780fc to your computer and use it in GitHub Desktop.
Create an array using Array.from() static method from an array-like object.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| /** | |
| * Create an array from an array-like object. | |
| * An array-like object is an object which has a length property | |
| * and indexed elements. An indexed element means the properties | |
| * of the object are like the index of an array. | |
| * | |
| * @author Sajeeb Ahamed <sajeeb07ahamed@gmail.com> | |
| */ | |
| const arrayLikeObject = { | |
| 0: 'riki', | |
| 1: 'axe', | |
| 2: 'lich', | |
| 3: 'phantom assassin', | |
| length: 4, | |
| }; | |
| const nameArray = Array.from(arrayLikeObject); | |
| console.log(nameArray); // [ 'riki', 'axe', 'lich', 'phantom assassin' ] |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment