Loading lesson path
Concept visual
Object.assign()
Object.create()
Object.fromEntries()
An object literal is a list of property key:values inside curly braces
{ }.
{firstName:"John", lastName:"Doe", age:50, eyeColor:"blue"};// Create an Object const person = {
firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue"
};// Create an Object const person = new Object({
firstName: "John", lastName: "Doe", age: 50, eyeColor: "blue"
});The examples above do exactly the same. But, there is no need to use new Object(). For readability, simplicity and execution speed, use the object literal method. Objects written as name value pairs are similar to:
JavaScript Object.create()
Object.create() method creates an object from an existing object.
// Create an Object:
const person = {
firstName: "John", lastName: "Doe"
};
// Create new Object const man = Object.create(person);
man.firstName = "Peter";to JavaScript.
Formula
method creates an object from iterable key / value pairs.const fruits = [
["apples", 300],
["pears", 900],
["bananas", 500]
];
const myObj = Object.fromEntries(fruits);