How to remove a position from an Arraybuffer in javascript?

Asked

Viewed 56 times

0

I have this Arraybuffer below and I need to remove from this array the position that has the value 21

I’ve tried using the splice(24,1) and also the delete array[24] and none worked?

Does anyone know how I can just remove that position from Arraybuffer?

<Buffer 01 a6 31 35 cb 12 00 08 7d cb b8 ae c5 3e 2d 0e 1e d0 fe 29 4e 61 fd 01 21 a0 00 c0 03 00 00 00 00 00 00 00 00 00 04 24 03 19 15 cb 0b 3b 26 06 0b 31 00 ...>
  • How did you do with splice(24.1) so it doesn’t work? You can post the code to us?

  • if (package[i].toString(16) == 10) { package[i] = parseint(package[i + 1].toString(16)) - 20; package.splice(i + 1, 1); }

  • Returning this: package.splice(i + 1, 1); Typeerror: Object 15 @Paulohdsousa

2 answers

0

Just use the operator '-='. Let’s imagine that we have the following:

val valor = ArrayBuffer('1', '2', '3', '4', '21')

To remove the value 21:

valor -= '21'

If we want to eliminate more than one value:

valor -= ('21', '4')
  • is returning Nan the new array, remembering that it is an Arraybuffer of Bytes

  • and if it has two values 21?

0

You can do so, that it will remove the element from the array:

 ArrayBuffer.forEach(function(value, index) {
       if (value == '21') {
            ArrayBuffer.splice(index, 1);
       }
 });

See working here

Browser other questions tagged

You are not signed in. Login or sign up in order to post.