Skip to content

Instantly share code, notes, and snippets.

@ahamed
Created August 18, 2022 06:55
Show Gist options
  • Select an option

  • Save ahamed/313a0f7cf527ffbbb8b015094ee780fc to your computer and use it in GitHub Desktop.

Select an option

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.
/**
* 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