如何获取特定元素的所有数据属性的长度?

How can i geht the lenght of all data-attributes of an specific elements?

HTML:

<div id="me" data-property-1="1" data-property-2="2" data-property-3="3"></div>

是否可以使用 vanilla.js 获取 div 的所有数据属性的长度?

你能试试这个吗:

const dataSetLength = Object.keys(document.getElementById('me').dataset).length;
console.log('Length of dataset:', dataSetLength);
<div id="me" data-property-1="1" data-property-2="2" data-property-3="3"></div>