I have a passcode or OTP input modal to verify the user's email and phone number.
<form>
 <span id="ap-email-otp" class="actions-pack-otp">
   <input type="tel" class="ap-otp-input" data-channel="email" data-index="0" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="email" data-index="1" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="email" data-index="2" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="email" data-index="3" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="email" data-index="4" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="email" data-index="5" maxlength="1" required>
 </span>
 <span id="ap-phone-otp" class="actions-pack-otp">
   <input type="tel" class="ap-otp-input" data-channel="phone" data-index="0" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="phone" data-index="1" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="phone" data-index="2" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="phone" data-index="3" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="phone" data-index="4" maxlength="1" required>
   <input type="tel" class="ap-otp-input" data-channel="phone" data-index="5" maxlength="1" required>
 </span>
</form>
 I want to update an object
I want to update an object otp on every keyup event.
otp = {};
$document.on('keyup', '.ap-otp-input', function (e){
    if( e.keyCode === 8 || e.keyCode === 37 ){
        $(this).prev(':input').focus();
    }
    else{
        $(this).next(':input').focus();
    }
    otp[$(this).attr('data-channel')] = Array(6).splice( $(this).attr('data-index'), 0, $(this).val());
});
Output Getting:
otp{
  email : [], // Empty array
  phone : [], // Empty array
}
Expected Output Value of input should be inserted at it's data index.
Note : The "channel" names i.e email, phone etc are not predictable. It is dynamically calculated from the input's data-channel attribute.
 
    