How to use Object.keys() and toLowerCase() Methods In Javascript
The approach here is the same as in the previous example, The Object.keys() method is used and the operation is performed in a compact manner.
Example: This example shows the use of the above-explained approach.
javascript
let GFG_Object = { a: "Val_1" , n: "Val_2" , c: "Val_3" , b: "Val_4" , }; function GFG_Run() { let ObjKey = "A" ; console.log( "Key: '" + ObjKey + "'\nValue: '" + GFG_Object[Object.keys(GFG_Object).find( (key) => key.toLowerCase() === ObjKey.toLowerCase())] + "'" ); } GFG_Run(); |
Output
Key: 'A' Value: 'Val_1'
Access Object property case-insensitively in JavaScript
In this article, we will see how to access an object’s properties without case-sensitivity, In this article, we are discussing how to access object property case-insensitively in JavaScript.
- Using toLowerCase() and Object.hasOwnProperty() Methods
- Using Object.keys() and toLowerCase() Methods
Contact Us