Outils pour utilisateurs

Outils du site


faire_un_dump_dans_la_console

Ceci est une ancienne révision du document !


Faire un dump dans la console

Javascript - var_dump - print_r - console

dmp = (what, pre = '', depth = 50) => {
	if (typeof what == 'undefined') {
		return '*undefined*'
	}
	if (typeof what == 'null') {
		return '*null*'
	}
	for (const anti of anticyclic) {
		if (what === anti) {
			return '*cycle*'
		}
	}
	anticyclic.push(what)
	if (depth && Array.isArray(what)) {
		let result = "Array: [\n"
    let key = 0
		for (const value of what) {
			result += pre + '.' + key + ': ' + dmp(value, pre + '.' + key, depth - 1) + "\n"
      key ++
		}
		return result + ']'
	}
	else if (depth && typeof what === 'object') {
		let result = "Object: {\n"
		for (const key in what) if (what.hasOwnProperty(key)) {
			result += pre + '.' + key + ': ' + dmp(what[key], pre + '.' + key, depth - 1) + "\n"
		}
		return result + '}'
	}
	return what.toString()
}
anticyclic = []
dmp(application)
faire_un_dump_dans_la_console.1668108067.txt.gz · Dernière modification : 2022/11/10 20:21 de tickleman