data = [ RowDataPacket { test: '12312311' },
RowDataPacket { test: '12312312' },
RowDataPacket { test: '12312313' } ]
I would like to get the numbers from this object into an array in Javascript.
I already tried it with .split(/(\d+)/);
but I get this error in Chrome:
Uncaught TypeError: data.split is not a function.
How can I extract the numbers?
Your attempt will not work because .split()
is a string method - it's used for breaking up a string into an array. You already have an array. JSON seems to be irrelevant here, as what you've shared is not JSON.
You can use Array.map()
to mutate each member of an array. You want to get each member's test
value, and parse it.
var data = [ { test: '12312311' }, { test: '12312312' }, { test: '12312313' } ];
var result = data.map(obj => parseInt(obj.test));
console.log(result);
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With