<div id="dynamicTable" columns="26,40,41,21,71,39,23,19">
var columns = $('#dynamicTable').attr('columns'); var attributeIds = new Array(); attributeIds = columns.split(',');
This creates an array of strings, I need them to be ints. What's the best way to do this?
You could use $.parseJSON
.
Example: http://jsfiddle.net/ULkXy/
var columns = $('#dynamicTable').attr('columns');
var attributeIds = $.parseJSON( '[' + columns + ']' );
Here's another way using a while
loop with the unary +
operator:
Example: http://jsfiddle.net/ULkXy/1/
var columns = $('#dynamicTable').attr('columns');
var attributeIds = columns.split(',');
var len = attributeIds.length;
while( len-- ) {
attributeIds[len] = +attributeIds[len];
}
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