Say we have this:
const v = [1,2,3];
v.foo = 5;
console.log(JSON.stringify(v));
we will get:
'[1,2,3]'
and the 'foo' property on the array will be ignored. However, if we do:
console.log(Object.keys(v));
we will get:
[ '0', '1', '2', 'foo' ]
my question is - how can we get only the standard keys from an array, and ignore any properties that were tacked onto the array?
The only way I know how to do this would be something like:
const keys = Object.keys(v).filter(k => Number.isInteger(parseInt(k)));
is there a better way?