Learn Flexbox with Images
Use beautiful images to learn CSS Flexbox.
Find out moreWhenever you use Object.entries() on a JavaScript object, the method does the following:
Object.entries()
MethodObject.entries()
accepts a single argument. Here’s the syntax:
Object.entries(objectArgument);
The objectArgument
refers to the JavaScript object whose key-value pairs you want to extract into a new array.
Object.entries()
MethodBelow are examples of the Object.entries()
method.
const profile = { firstName: "Oluwatobi", lastName: "Sofela", companyName: "CodeSweetly", npmPackage: "@codesweetly/react-youtube-playlist",};
const formData = Object.entries(profile);
console.log(formData);
// The invocation above will return:// [// ["firstName", "Oluwatobi"],// ["lastName", "Sofela"],// ["companyName", "CodeSweetly"],// ["npmPackage", "@codesweetly/react-youtube-playlist"],// ["id", 9103],// ]
const myBio = ["Oluwatobi", "Sofela", "CodeSweetly", 9103];
const itemsInMyBio = Object.entries(myBio);
console.log(itemsInMyBio);
// The invocation above will return:// [// ["0", "Oluwatobi"],// ["1", "Sofela"],// ["2", "CodeSweetly"],// ["3", 9103],// ]
const firstName = "Oluwatobi";
const itemsInFirstName = Object.entries(firstName);
console.log(itemsInFirstName);
// The invocation above will return:// [// ["0", "O"],// ["1", "l"],// ["2", "u"],// ["3", "w"],// ["4", "a"],// ["5", "t"],// ["6", "o"],// ["7", "b"],// ["8", "i"],// ]
The Object.entries()
method successfully extracted the string’s key-value pairs because strings are the only primitive data with enumerable own properties.