Use filter for the above two steps:

keyframes = keyframes.filter(function(frame) { return !isDefinedAndNotNull(offset) || (frame.offset >= 0 && frame.offset <= 1); });