Skip to content

Instantly share code, notes, and snippets.

@Jon20111
Created April 17, 2020 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Jon20111/e84e8767c409085be9d837199292cfc2 to your computer and use it in GitHub Desktop.
Save Jon20111/e84e8767c409085be9d837199292cfc2 to your computer and use it in GitHub Desktop.
Convert 2-Dimension Array to Object
export const twoDimArrayToObject = function(array: string[][]) {
const returnObject: {
[key: string]: string
} = {};
array.forEach((element) => {
returnObject[element[0]] = element[1];
})
return returnObject;
}
@Jon20111
Copy link
Author

This Javascript utility transforms a 2-d array to an object with proper typing. I'm happy to answer any questions or see my brief write-up here:
https://smartdevpreneur.com/transform-2-d-string-array-to-object-using-typescript-and-javascript/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment