Created
October 23, 2020 22:47
-
-
Save mcalavera81/d1f9428999a5c2ea3fcaef6c1ca7bbca to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| function ConvertKeysToLowerCase(obj) { | |
| if (!obj || typeof obj !== "object") { | |
| return obj; | |
| } | |
| var output = {}; | |
| for (let i in obj) { | |
| if (Object.prototype.toString.apply(obj[i]) === '[object Object]') { | |
| output[i.toLowerCase()] = ConvertKeysToLowerCase(obj[i]); | |
| }else if(Object.prototype.toString.apply(obj[i]) === '[object Array]'){ | |
| output[i.toLowerCase()]=[]; | |
| for (const z of obj[i]){ | |
| output[i.toLowerCase()].push(ConvertKeysToLowerCase(z)); | |
| } | |
| } else { | |
| output[i.toLowerCase()] = obj[i]; | |
| } | |
| } | |
| return output; | |
| }; | |
| let a ={ | |
| Pepe:[{ | |
| LIBRO: "PEPE", | |
| MANSION:{ | |
| "a":1 | |
| } | |
| },{ | |
| LIBRO: "PEPE", | |
| MANSION:{ | |
| "a":1 | |
| } | |
| }], | |
| CASA: "SI", | |
| Perro:{ | |
| LIBRO: "PEPE", | |
| MANSION:{ | |
| "a":1 | |
| } | |
| } | |
| } | |
| console.log(JSON.stringify(ConvertKeysToLowerCase(a),null,2)) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment