Node.js console.dirxml() 方法将在执行时通过 dirxml() 方法传递接收到的参数来调用 console.log() 方法。此方法不会生成任何 XML 格式。
假设存在一个具有属性和值的对象。如果我们将对象名称传递给 console.dirxml() 方法,它将通过传递收到的参数(对象)来调用 console.log 方法。因此,它将在输出中显示对象的属性。
语法
以下是Node.js console.dirxml() 方法的语法 -
console.dirxml(data)
参数
- data − 此参数接受 JavaScript 对象或元素。
返回值
此方法将返回已传递的对象或元素。
例Node.js console.dirxml() 方法将只接受一个参数。
在下面的示例中,我们将创建一个具有可枚举属性的对象。然后我们将对象作为参数传递给 node.js 的 console.dirxml() 方法。
var Family = {
Husband : "Jack",
wife : "Rose",
MarrDuration : "25 years",
Kids : 1,
KidName : "Jase",
}
console.dirxml(Family);
输出
正如我们在输出中看到的,这里的族是一个对象,我们将其传递给 console.dirxml() 方法,然后该方法将通过传递收到的参数来调用 console.log() 方法。
{
Husband: 'Jack',
wife: 'Rose',
MarrDuration: '25 years',
Kids: 1,
KidName: 'Jase'
}
Husband: 'Jack',
wife: 'Rose',
MarrDuration: '25 years',
Kids: 1,
KidName: 'Jase'
}
例
node.js 的 console.dirxml() 方法将只接受一个参数。
在此示例中,我们将一个整数值作为参数传递给 node.js 的 console.dirxml() 方法。
var x = 10;
var y = 10;
var z = x + y;
console.dirxml(z);
输出
正如我们在输出中看到的,我们将一个整数值传递给 console.dirxml() 方法,然后该方法将通过传递收到的参数来调用 console.log() 方法。
20
例
在此示例中,我们将字符串作为输入传递给 console.dirxml() 方法。
console.dirxml("qikepu, Simply Easy Learning at your fingertips");
输出
正如我们在输出中看到的,作为参数传递的输入字符串将被打印出来。
qikepu, Simply Easy Learning at your fingertips