Use Flexbox like a pro
Learn CSS Flexbox with live examples and images.
Check it outWhenever you use Object.keys() on a JavaScript object, the method does the following:
Object.keys()
MethodObject.keys()
accepts a single argument. Here’s the syntax:
Object.keys(objectArgument);
The objectArgument
refers to the JavaScript object whose keys (property names) you want to extract into a new array.
Object.keys()
MethodBelow are examples of the Object.keys()
method.
const profile = { firstName: "Oluwatobi", lastName: "Sofela", companyName: "CodeSweetly", npmPackage: "@codesweetly/react-youtube-playlist",};
const formFieilds = Object.keys(profile);
console.log(formFieilds);
// The invocation above will return:// ["firstName", "lastName", "companyName", "npmPackage", "id"]
const myBio = ["Oluwatobi", "Sofela", "CodeSweetly", 9103];
const keysInMyBio = Object.keys(myBio);
console.log(keysInMyBio);
// The invocation above will return:// ["0", "1", "2", "3"]
const firstName = "Oluwatobi";
const keysInFirstName = Object.keys(firstName);
console.log(keysInFirstName);
// The invocation above will return:// ["0", "1", "2", "3", "4", "5", "6", "7", "8"]
The Object.keys()
method successfully extracted the string’s keys because strings are the only primitive data with enumerable own properties.