Outils pour utilisateurs

Outils du site


faire_un_dump_dans_la_console

Différences

Ci-dessous, les différences entre deux révisions de la page.

Lien vers cette vue comparative

Les deux révisions précédentesRévision précédente
Prochaine révision
Révision précédente
faire_un_dump_dans_la_console [2022/11/10 20:21] ticklemanfaire_un_dump_dans_la_console [2022/11/25 13:05] (Version actuelle) tickleman
Ligne 2: Ligne 2:
  
 Javascript - var_dump - print_r - console Javascript - var_dump - print_r - console
 +
 +Vous pouvez copier-coller ça dans votre navigateur : ça fera un dump récursif de votre variable application (à remplacer par ce qui vous intéresse) dans un format qui va vous aider à retrouver vos données :
  
 <code javascript> <code javascript>
-dmp = (what, pre = '', depth = 50) => { +dmp = (what, pre = '', depth = 100) => { 
- if (typeof what == 'undefined'+    if (depth === 100) anticyclic = {} 
- return '*undefined*' +    if (typeof what == 'undefined') return '*undefined*' 
- +    if (typeof what == 'null') return '*null*' 
- if (typeof what == 'null'+    for (const anti in anticyclic) if (anticyclic.hasOwnProperty(anti) && (anticyclic[anti] === what)) return '*cycle* ' + anti 
- return '*null*' +    if (!depth) return what.toString(
- +    if (Array.isArray(what)) { 
- for (const anti of anticyclic) +        anticyclic[pre] = what 
- if (what === anti+        let result = "Array: [\n" 
- return '*cycle*' +        let key = 0 
- +        for (const value of what) { 
-+            result += pre + '.' + key + ': ' + dmp(value, pre + '.' + key, depth - 1) + "\n" 
- anticyclic.push(what) +            key ++ 
- if (depth && Array.isArray(what)) { +        
- let result = "Array: [\n" +        return result + ']' 
-    let key = 0 +    
- for (const value of what) { +    else if (typeof what === 'object') { 
- result += pre + '.' + key + ': ' + dmp(value, pre + '.' + key, depth - 1) + "\n" +        anticyclic[pre] = what 
-      key ++ +        let result = "Object: {\n" 
- +        for (const key in what) if (what.hasOwnProperty(key)) { 
- return result + ']' +            result += pre + '.' + key + ': ' + dmp(what[key], pre + '.' + key, depth - 1) + "\n" 
-+        
- else if (depth && typeof what === 'object') { +        return result + '}' 
- let result = "Object: {\n" +    
- for (const key in what) if (what.hasOwnProperty(key)) { +    return what.toString()
- result += pre + '.' + key + ': ' + dmp(what[key], pre + '.' + key, depth - 1) + "\n" +
- +
- return result + '}' +
-+
- return what.toString()+
 } }
-anticyclic = [] 
 dmp(application) dmp(application)
 </code> </code>
- 
- 
faire_un_dump_dans_la_console.1668108086.txt.gz · Dernière modification : 2022/11/10 20:21 de tickleman