I'm writing a script that will split the element's ID from the format 'note-1192' (for example) and place it into an array:
var timers = new Array();
$('.notes').keyup(function(){
var timerVariable = $(this).attr('id').split("-");
timerVariable = timerVariable[0];
timerVariable = timerVariable.replace('note', '');
alert(timerVariable); // 1192
timers[timerVariable] = timerVariable;
alert(timers.join('\n')); // blank
});
It's not storing the variable into the array at all, when I alert the 'timers array' it's empty, but when I alert the 'timerVariable' it comes out just fine.
Any suggestions would be very welcome, thanks!
join()there are going to a a lot of empty lines before your data.var timerVariable = $(this).attr('id').split("-");so nowtimerVariableis an array, with 'note' at position 0 and '1192' at position 1. Then,timerVariable = timerVariable[0];so nowtimerVariableis just 'note'. How did you end up with 1192 when you alerted?