#JavaScript #Programming #WebDevelopment #ES8 #Objects #ObjectValues #ObjectEntries #Coding #Developer #Tech #Tutorial #learnjavascript #Fronten #SoftwareDevelopment #CodeNewbie #DeveloperCommunity #JavaScriptTutorial #ProgrammingTips #JS #JavaScriptObjects
Introductions
Object.values() and Object.entries() are two static methods introduced in ECMAScript 2017 (ES8) for working with objects in JavaScript.
Object.values():
The Object.values() method returns an array containing the values of an object's enumerable properties.
Syntax:
JavaScript code:
Object.values(obj)
obj: The object whose enumerable property values are to be returned.
Example:
JavaScript code:
const obj = { a: 1, b: 2, c: 3 };
const values = Object.values(obj);
console.log(values); // Output: [1, 2, 3]
Object.entries():
The Object.entries() method returns an array containing arrays of key-value pairs for each enumerable property in an object.
Syntax:
JavaScript code:
Object.entries(obj)
obj: The object whose enumerable property key-value pairs are to be returned.
Example:
JavaScript code:
const obj = { a: 1, b: 2, c: 3 };
const entries = Object.entries(obj);
console.log(entries); // Output: [['a', 1], ['b', 2], ['c', 3]]
Advantages:
Convenience: Both methods provide convenient ways to work with objects, simplifying tasks like iterating over object properties or extracting values.
Consistency: They provide a consistent way to handle object properties, aligning with other methods like Object.keys().
Compatibility:
Object.values() and Object.entries() are available in modern browsers and Node.js environments. For older environments, you may need to use polyfills or transpile your code.
Use Cases:
Iterating over object properties.
Converting object properties into arrays for further processing or manipulation.
Checking for the presence of specific values or key-value pairs in an object.
Summery
Overall, Object.values() and Object.entries() are powerful additions to JavaScript's standard library, offering convenient ways to work with object data structures.
Chapter :
00:00 Introduction
00:25 Syntax - Object.Values()
00:42 Example - Object.Values()
00:59 Syntax - Object.entries()
01:17 Example - Object.entries()
01:36 Advantages
01:59 Compatibility & Use Cases
02:19 Summery
Thank you for watching this video
EVERYDAY BE CODING