Convert array to object keys

Miguel Stevens

What's the best way to convert an array, to an object with those array values as keys, empty strings serve as the values of the new object.

['a','b','c']

to:

{
  a: '',
  b: '',
  c: ''
}
prasanth

try with Array#Reduce

const arr = ['a','b','c'];
const res = arr.reduce((a,b)=> (a[b]='',a),{});
console.log(res)

この記事はインターネットから収集されたものであり、転載の際にはソースを示してください。

侵害の場合は、連絡してください[email protected]

編集
0

コメントを追加

0

関連記事

分類Dev

convert object keys and values to an array of objects

分類Dev

Convert Javascript Object keys to strings

分類Dev

Convert array from with keys to without keys

分類Dev

Match object by array keys - Lodash

分類Dev

turn array of object into keys failed

分類Dev

Convert laravel object to array

分類Dev

Javascript - Convert object to array object

分類Dev

How to convert array to object in Javascript?

分類Dev

Filter Array of object based in duplicate keys

分類Dev

Find value from an object and array of keys

分類Dev

Convert object to array and group them by object key

分類Dev

Convert jagged int[][] array to object[][] array

分類Dev

Struggling to convert an Object to have keys within one of the sub objects

分類Dev

How to convert array keys into random string in php laravel

分類Dev

What is the easiest way to convert array with keys to other format

分類Dev

Convert array of objects with nested array of objects into array-like object

分類Dev

How to convert an array into an object using stdClass()

分類Dev

Convert object to associative array returns null value

分類Dev

Rethinkdb convert an array of objects to a single object

分類Dev

Convert an array of objects to a hash based on a property of the object

分類Dev

Unable to convert a nested object into an array of objects and viceversa

分類Dev

Convert string separated by comma in json object to array

分類Dev

Convert JSON Array to Object Node js

分類Dev

Convert object to array and map name as key and children

分類Dev

Loop Array of Object and connect them together by different keys

分類Dev

How to convert square bracket object keys from URL location into nested object in Javascript?

分類Dev

Define type to convert array of keyed object to indexed object in typescript

分類Dev

Convert a simple Array to complex Object with items as child array

分類Dev

Merge 2 array present in object of available keys be removing specific property of object

Related 関連記事

  1. 1

    convert object keys and values to an array of objects

  2. 2

    Convert Javascript Object keys to strings

  3. 3

    Convert array from with keys to without keys

  4. 4

    Match object by array keys - Lodash

  5. 5

    turn array of object into keys failed

  6. 6

    Convert laravel object to array

  7. 7

    Javascript - Convert object to array object

  8. 8

    How to convert array to object in Javascript?

  9. 9

    Filter Array of object based in duplicate keys

  10. 10

    Find value from an object and array of keys

  11. 11

    Convert object to array and group them by object key

  12. 12

    Convert jagged int[][] array to object[][] array

  13. 13

    Struggling to convert an Object to have keys within one of the sub objects

  14. 14

    How to convert array keys into random string in php laravel

  15. 15

    What is the easiest way to convert array with keys to other format

  16. 16

    Convert array of objects with nested array of objects into array-like object

  17. 17

    How to convert an array into an object using stdClass()

  18. 18

    Convert object to associative array returns null value

  19. 19

    Rethinkdb convert an array of objects to a single object

  20. 20

    Convert an array of objects to a hash based on a property of the object

  21. 21

    Unable to convert a nested object into an array of objects and viceversa

  22. 22

    Convert string separated by comma in json object to array

  23. 23

    Convert JSON Array to Object Node js

  24. 24

    Convert object to array and map name as key and children

  25. 25

    Loop Array of Object and connect them together by different keys

  26. 26

    How to convert square bracket object keys from URL location into nested object in Javascript?

  27. 27

    Define type to convert array of keyed object to indexed object in typescript

  28. 28

    Convert a simple Array to complex Object with items as child array

  29. 29

    Merge 2 array present in object of available keys be removing specific property of object

ホットタグ

アーカイブ