Object.fromEntries
This method is used to convert an array of key-value pairs into an object.
fromEntries
method takes an fromEntries
method returns a new object created from the iterable object passed as an argument.We can use fromEntries
to clone an object. To do this, you need to convert the object to entries and create the object using fromEntries
.
Make sure that only the key-value pair is passed; otherwise, there will be an error.
// TypeError will be thrown in all the below case
Object.fromEntries(undefined)
Object.fromEntries(null)
Object.fromEntries(true)
Object.fromEntries(100)
Object.fromEntries("hi")
Object.fromEntries({key: "value"})
Object.fromEntries([1,2,3])
RELATED TAGS
CONTRIBUTOR
View all Courses